File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
packages/workers-shared/router-worker Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/workers-shared " : patch
3+ ---
4+
5+ allow plain text with charset
Original file line number Diff line number Diff line change @@ -136,12 +136,18 @@ export default {
136136
137137 if ( shouldBlockNonImageResponse ) {
138138 const resp = await env . USER_WORKER . fetch ( maybeSecondRequest ) ;
139- const isImage = resp . headers
140- . get ( "content-type" )
141- ?. startsWith ( "image/" ) ;
142- const isPlainText =
143- resp . headers . get ( "content-type" ) === "text/plain" ;
144- if ( ! isImage && ! isPlainText && resp . status !== 304 ) {
139+
140+ const contentType = resp . headers . get ( "content-type" ) || "" ;
141+
142+ // Allow:
143+ // - images
144+ // - text/plain - used by Next errors
145+ const isImageOrPlainText =
146+ contentType . startsWith ( "image/" ) ||
147+ // Matches "text/plain", "text/plain;charset=UTF-8"
148+ contentType . split ( ";" ) [ 0 ] === "text/plain" ;
149+
150+ if ( ! isImageOrPlainText && resp . status !== 304 ) {
145151 analytics . setData ( { abuseMitigationBlocked : true } ) ;
146152 return new Response ( "Blocked" , { status : 403 } ) ;
147153 }
Original file line number Diff line number Diff line change @@ -313,6 +313,18 @@ describe("unit tests", async () => {
313313 expectedStatus : 200 ,
314314 expectedBody : "fake image data" ,
315315 } ,
316+ {
317+ description :
318+ "allows /_next/image requests with remote URLs that have content type text/plain with charset" ,
319+ url : `https://example.com${ subpath } _next/image?url=https://example.com/image.jpg` ,
320+ userWorkerResponse : {
321+ body : "fake image data" ,
322+ headers : { "content-type" : "text/plain;charset=UTF-8" } ,
323+ status : 200 ,
324+ } ,
325+ expectedStatus : 200 ,
326+ expectedBody : "fake image data" ,
327+ } ,
316328 {
317329 description :
318330 "allows /_next/image with remote URL and image header regardless of response content" ,
You can’t perform that action at this time.
0 commit comments