File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
packages/workers-shared/router-worker/src Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/workers-shared " : minor
3+ ---
4+
5+ Block /\_ image routes with href query param using double slash.
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ type Data = {
5353 coloRegion ?: string ;
5454 // blob6 - URL for analysis
5555 abuseMitigationURLHost ?: string ;
56+ // blob7 - XSS detection href parameter value
57+ xssDetectionImageHref ?: string ;
5658} ;
5759
5860export class Analytics {
@@ -107,6 +109,7 @@ export class Analytics {
107109 this . data . version , // blob4
108110 this . data . coloRegion , // blob5
109111 this . data . abuseMitigationURLHost , // blob6
112+ this . data . xssDetectionImageHref , // blob7
110113 ] ,
111114 } ) ;
112115 }
Original file line number Diff line number Diff line change @@ -128,6 +128,28 @@ export default {
128128 }
129129 }
130130
131+ if ( url . pathname === "/_image" ) {
132+ const hrefParam = url . searchParams . get ( "href" ) ;
133+ if (
134+ hrefParam &&
135+ hrefParam . length > 2 &&
136+ hrefParam . startsWith ( "//" )
137+ ) {
138+ try {
139+ const hrefUrl = new URL ( "https:" + hrefParam ) ;
140+ const isImageFetchDest =
141+ request . headers . get ( "sec-fetch-dest" ) == "image" ;
142+
143+ if ( hrefUrl . hostname !== url . hostname && ! isImageFetchDest ) {
144+ analytics . setData ( { xssDetectionImageHref : hrefParam } ) ;
145+ return new Response ( "Blocked" , { status : 403 } ) ;
146+ }
147+ } catch {
148+ console . log ( `Invalid href parameter in /_image: ${ hrefParam } ` ) ;
149+ }
150+ }
151+ }
152+
131153 analytics . setData ( {
132154 timeToDispatch : performance . now ( ) - startTimeMs ,
133155 } ) ;
You can’t perform that action at this time.
0 commit comments