File tree Expand file tree Collapse file tree
packages/docusaurus-plugin-pwa/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments