From 007025f2668391889c68521b932018933c0a2047 Mon Sep 17 00:00:00 2001 From: ADITYA CHAUHAN <125276621+hooiv@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:35:22 +0530 Subject: [PATCH] Add examples for X-Content-Type-Options header Add examples for X-Content-Type-Options header Addresses issue [#636](https://github.com/whatwg/fetch/issues/636) by adding comprehensive examples to the 'Should response to request be blocked due to nosniff?' algorithm. The examples clarify: - When responses are blocked (MIME type mismatch, missing Content-Type) - When responses are allowed (correct MIME type, no X-Content-Type-Options header) - Different request destinations (script, style, image) This should help web developers and implementers understand the exact behavior of the X-Content-Type-Options: nosniff directive. --- fetch.bs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/fetch.bs b/fetch.bs index 4d01e315b..85ca5f9fe 100755 --- a/fetch.bs +++ b/fetch.bs @@ -4030,6 +4030,53 @@ X-Content-Type-Options = "nosniff" ; case-insensitive
Only request destinations that are
script-like or "style
" are considered as any exploits
pertain to them. Also, considering "image
" was not compatible with deployed content.
+
+
The following examples illustrate how the algorithm works: + +
A request for a JavaScript file with destination
+ "script
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and
+ `Content-Type
: application/javascript
` will return allowed
+ (JavaScript MIME type matches script-like destination).
+
+
A request for a JavaScript file with destination
+ "script
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and
+ `Content-Type
: text/html
` will return blocked
+ (MIME type mismatch: HTML is not a JavaScript MIME type).
+
+
A request for a JavaScript file with destination
+ "script
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and no
+ `Content-Type
` header will return blocked
+ (no MIME type provided, so mimeType is failure).
+
+
A request for a CSS file with destination
+ "style
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and
+ `Content-Type
: text/css
` will return allowed
+ (CSS MIME type matches style destination).
+
+
A request for a CSS file with destination
+ "style
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and
+ `Content-Type
: application/javascript
` will return blocked
+ (MIME type mismatch: JavaScript is not text/css).
+
+
A request for an image with destination
+ "image
" to a response that has
+ `X-Content-Type-Options
: nosniff
` and
+ `Content-Type
: text/html
` will return allowed
+ (image destinations are not checked by this algorithm).
+
+
A request for a JavaScript file with destination
+ "script
" to a response that does not have an
+ `X-Content-Type-Options
` header will return allowed
+ (no nosniff directive present).
+