Skip to content

Commit a6b34af

Browse files
Validate GET_COOKIE payload
1 parent 7a23fb4 commit a6b34af

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

src/background/index.mjs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,38 @@ Browser.runtime.onMessage.addListener(async (message, sender) => {
728728
return null
729729
}
730730

731-
console.debug('[background] Processing GET_COOKIE message for:', message.data?.url)
731+
const cookieUrlInput = message?.data?.url
732+
const cookieNameInput = message?.data?.name
733+
if (
734+
typeof cookieUrlInput !== 'string' ||
735+
!cookieUrlInput.trim() ||
736+
typeof cookieNameInput !== 'string' ||
737+
!cookieNameInput.trim()
738+
) {
739+
console.warn('[background] Rejecting GET_COOKIE with invalid payload:', message.data)
740+
return null
741+
}
742+
743+
let cookieUrl
744+
try {
745+
cookieUrl = new URL(cookieUrlInput.trim())
746+
} catch (error) {
747+
console.warn('[background] Rejecting GET_COOKIE with invalid URL:', cookieUrlInput)
748+
return null
749+
}
750+
751+
const cookieName = cookieNameInput.trim()
752+
console.debug('[background] Processing GET_COOKIE message for:', cookieUrl.href)
732753
try {
733754
const cookie = await Browser.cookies.get({
734-
url: message.data.url,
735-
name: message.data.name,
755+
url: cookieUrl.href,
756+
name: cookieName,
736757
})
737758
console.debug('[background] Cookie found:', cookie ? 'yes' : 'no')
738759
return cookie?.value
739760
} catch (error) {
740761
console.error(
741-
`[background] Error getting cookie ${message.data.name} for ${message.data.url}:`,
762+
`[background] Error getting cookie ${cookieName} for ${cookieUrl.href}:`,
742763
error,
743764
)
744765
return null

0 commit comments

Comments
 (0)