File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -781,17 +781,38 @@ Browser.runtime.onMessage.addListener(async (message, sender) => {
781781 return null
782782 }
783783
784- console . debug ( '[background] Processing GET_COOKIE message for:' , message . data ?. url )
784+ const cookieUrlInput = message ?. data ?. url
785+ const cookieNameInput = message ?. data ?. name
786+ if (
787+ typeof cookieUrlInput !== 'string' ||
788+ ! cookieUrlInput . trim ( ) ||
789+ typeof cookieNameInput !== 'string' ||
790+ ! cookieNameInput . trim ( )
791+ ) {
792+ console . warn ( '[background] Rejecting GET_COOKIE with invalid payload:' , message . data )
793+ return null
794+ }
795+
796+ let cookieUrl
797+ try {
798+ cookieUrl = new URL ( cookieUrlInput . trim ( ) )
799+ } catch ( error ) {
800+ console . warn ( '[background] Rejecting GET_COOKIE with invalid URL:' , cookieUrlInput )
801+ return null
802+ }
803+
804+ const cookieName = cookieNameInput . trim ( )
805+ console . debug ( '[background] Processing GET_COOKIE message for:' , cookieUrl . href )
785806 try {
786807 const cookie = await Browser . cookies . get ( {
787- url : message . data . url ,
788- name : message . data . name ,
808+ url : cookieUrl . href ,
809+ name : cookieName ,
789810 } )
790811 console . debug ( '[background] Cookie found:' , cookie ? 'yes' : 'no' )
791812 return cookie ?. value
792813 } catch ( error ) {
793814 console . error (
794- `[background] Error getting cookie ${ message . data . name } for ${ message . data . url } :` ,
815+ `[background] Error getting cookie ${ cookieName } for ${ cookieUrl . href } :` ,
795816 error ,
796817 )
797818 return null
You can’t perform that action at this time.
0 commit comments