Skip to content

Commit 1ebe719

Browse files
Validate GET_COOKIE payload
1 parent 32eb0ea commit 1ebe719

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
@@ -723,17 +723,38 @@ Browser.runtime.onMessage.addListener(async (message, sender) => {
723723
return null
724724
}
725725

726-
console.debug('[background] Processing GET_COOKIE message for:', message.data?.url)
726+
const cookieUrlInput = message?.data?.url
727+
const cookieNameInput = message?.data?.name
728+
if (
729+
typeof cookieUrlInput !== 'string' ||
730+
!cookieUrlInput.trim() ||
731+
typeof cookieNameInput !== 'string' ||
732+
!cookieNameInput.trim()
733+
) {
734+
console.warn('[background] Rejecting GET_COOKIE with invalid payload:', message.data)
735+
return null
736+
}
737+
738+
let cookieUrl
739+
try {
740+
cookieUrl = new URL(cookieUrlInput.trim())
741+
} catch (error) {
742+
console.warn('[background] Rejecting GET_COOKIE with invalid URL:', cookieUrlInput)
743+
return null
744+
}
745+
746+
const cookieName = cookieNameInput.trim()
747+
console.debug('[background] Processing GET_COOKIE message for:', cookieUrl.href)
727748
try {
728749
const cookie = await Browser.cookies.get({
729-
url: message.data.url,
730-
name: message.data.name,
750+
url: cookieUrl.href,
751+
name: cookieName,
731752
})
732753
console.debug('[background] Cookie found:', cookie ? 'yes' : 'no')
733754
return cookie?.value
734755
} catch (error) {
735756
console.error(
736-
`[background] Error getting cookie ${message.data.name} for ${message.data.url}:`,
757+
`[background] Error getting cookie ${cookieName} for ${cookieUrl.href}:`,
737758
error,
738759
)
739760
return null

0 commit comments

Comments
 (0)