Skip to content

Commit 542fa67

Browse files
author
Sarfraz Khan
committed
CO-620 resolving ReDoS snyk warning
1 parent 638f4b3 commit 542fa67

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • packages/docusaurus-plugin-pwa/src

packages/docusaurus-plugin-pwa/src/sw.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,22 @@ function getPossibleURLs(url: string) {
105105
for (const possibleURL of possibleURLs) {
106106
const cacheKey = controller.getCacheKeyForURL(possibleURL);
107107
if (cacheKey) {
108-
const cachedResponse = caches.match(cacheKey) as Promise<Response>;
108+
// Sanitize cacheKey to prevent ReDoS or injection
109+
// Only allow safe URL characters
110+
const safeCacheKey = cacheKey.replace(
111+
/[^\w.\-~:/?#[\]@!$&'()*+,;=%]/g,
112+
'',
113+
);
114+
const cachedResponse = caches.match(
115+
safeCacheKey,
116+
) as Promise<Response>;
109117
if (params.debug) {
110118
console.log('[Docusaurus-PWA][SW]: serving cached asset', {
111119
requestURL,
112120
possibleURL,
113121
possibleURLs,
114122
cacheKey,
123+
safeCacheKey,
115124
cachedResponse,
116125
});
117126
}

0 commit comments

Comments
 (0)