File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -754,17 +754,38 @@ Browser.runtime.onMessage.addListener(async (message, sender) => {
754754 return null
755755 }
756756
757- console . debug ( '[background] Processing GET_COOKIE message for:' , message . data ?. url )
757+ const cookieUrlInput = message ?. data ?. url
758+ const cookieNameInput = message ?. data ?. name
759+ if (
760+ typeof cookieUrlInput !== 'string' ||
761+ ! cookieUrlInput . trim ( ) ||
762+ typeof cookieNameInput !== 'string' ||
763+ ! cookieNameInput . trim ( )
764+ ) {
765+ console . warn ( '[background] Rejecting GET_COOKIE with invalid payload:' , message . data )
766+ return null
767+ }
768+
769+ let cookieUrl
770+ try {
771+ cookieUrl = new URL ( cookieUrlInput . trim ( ) )
772+ } catch ( error ) {
773+ console . warn ( '[background] Rejecting GET_COOKIE with invalid URL:' , cookieUrlInput )
774+ return null
775+ }
776+
777+ const cookieName = cookieNameInput . trim ( )
778+ console . debug ( '[background] Processing GET_COOKIE message for:' , cookieUrl . href )
758779 try {
759780 const cookie = await Browser . cookies . get ( {
760- url : message . data . url ,
761- name : message . data . name ,
781+ url : cookieUrl . href ,
782+ name : cookieName ,
762783 } )
763784 console . debug ( '[background] Cookie found:' , cookie ? 'yes' : 'no' )
764785 return cookie ?. value
765786 } catch ( error ) {
766787 console . error (
767- `[background] Error getting cookie ${ message . data . name } for ${ message . data . url } :` ,
788+ `[background] Error getting cookie ${ cookieName } for ${ cookieUrl . href } :` ,
768789 error ,
769790 )
770791 return null
You can’t perform that action at this time.
0 commit comments