Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/docusaurus-plugin-pwa/src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,22 @@ function getPossibleURLs(url: string) {
for (const possibleURL of possibleURLs) {
const cacheKey = controller.getCacheKeyForURL(possibleURL);
if (cacheKey) {
const cachedResponse = caches.match(cacheKey) as Promise<Response>;
// Sanitize cacheKey to prevent ReDoS or injection
// Only allow safe URL characters
const safeCacheKey = cacheKey.replace(
/[^\w.\-~:/?#[\]@!$&'()*+,;=%]/g,
'',
);
const cachedResponse = caches.match(
safeCacheKey,
) as Promise<Response>;
if (params.debug) {
console.log('[Docusaurus-PWA][SW]: serving cached asset', {
requestURL,
possibleURL,
possibleURLs,
cacheKey,
safeCacheKey,
cachedResponse,
});
}
Expand Down
Loading