/
Overview.src.html
1885 lines (1588 loc) · 48.9 KB
/
Overview.src.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<meta charset=utf-8>
<title>MIME Sniffing Standard</title>
<style>
@media print { [data-anolis-spec]::after { content:"[" attr(data-anolis-spec) "]"; font-size:.6em; vertical-align:super; text-transform:uppercase } }
</style>
<link rel=stylesheet href=http://www.whatwg.org/style/specification>
<link rel=icon href=http://www.whatwg.org/images/icon>
<div class=head>
<p><a class=logo href=http://www.whatwg.org/><img alt=WHATWG height=101 src=http://www.whatwg.org/images/logo width=101></a></p>
<h1>MIME Sniffing</h1>
<h2 class="no-num no-toc">Living Standard — Last Updated [DATE: 01 Jan 1901]</h2>
<dl>
<dt>This Version:
<dd>
<a href=http://mimesniff.spec.whatwg.org/>http://mimesniff.spec.whatwg.org/</a>
<dt>Participate:
<dd>
Send feedback to
<a href="http://www.whatwg.org/mailing-list">whatwg@whatwg.org</a>
(<a href="http://www.whatwg.org/mailing-list#specs">archives</a>)
or
<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WHATWG&component=MIME">file a bug</a>
(<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WHATWG&component=MIME&resolution=---">open bugs</a>)
<dd>
<a href="http://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
<dt>Version history:
<dd>
<a href=https://github.com/whatwg/mimesniff/commits>https://github.com/whatwg/mimesniff/commits</a>
<dd>
<a href=https://twitter.com/mimesniff>@mimesniff</a>
<dt>Editor:
<dd>
<a href="http://gphemsley.org/">Gordon P. Hemsley</a> <<a href="mailto:me@gphemsley.org">me@gphemsley.org</a>>
<dt>Past editors:
<dd>
Adam Barth <<a href="mailto:whatwg@adambarth.com">whatwg@adambarth.com</a>> (Google)
<dd>
Ian Hickson <<a href="mailto:ian@hixie.ch">ian@hixie.ch</a>> (Google)
</dl>
<script src=//dvcs.w3.org/hg/quirks-mode/raw-file/tip/file-bug.js async></script>
<p class=copyright>
<a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0 Universal</a>.
To the extent possible under law, the editor has waived all copyright and
related or neighboring rights to this work.
In addition, as of [DATE: 01 Jan 1901], the editor has made this
specification available under the
<a rel="license" href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0">Open Web Foundation Agreement Version 1.0</a>,
which is available at
http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
</div>
<h2 class="no-num no-toc">Abstract</h2>
<p>
Many web servers supply incorrect <code>Content-Type</code> header fields
with their HTTP responses.
In order to be compatible with these servers, user agents consider the
content of HTTP responses as well as the <code>Content-Type</code> header
fields when determining the effective media type of the response.
This document describes an algorithm for determining the effective media type
of HTTP responses that balances security and compatibility considerations.
<h2 class=no-num>Table of contents</h2>
<!--toc-->
<h2>Introduction</h2>
<p>
The HTTP <code>Content-Type</code> header field indicates the media type of
an HTTP response.
However, many HTTP servers supply a <code>Content-Type</code> that does not
match the actual contents of the response.
Historically, web browsers have tolerated these servers by examining the
content of HTTP responses in addition to the <code>Content-Type</code> header
field to determine the effective media type of the response.
<p>
Without a clear specification of how to "sniff" the media type, each user
agent has been forced to reverse-engineer the algorithms of other user agents
in order to maintain interoperability.
Inevitably, these efforts have not been entirely successful, resulting in
divergent behaviors among user agents.
In some cases, these divergent behaviors have had security implications, as a
user agent could interpret an HTTP response as a different media type than
the server intended.
<p>
These security issues are most severe when an "honest" server allows
potentially malicious users to upload their own files and then serves the
contents of those files with a low-privilege media type.
For example, if a server believes that the client will treat a contributed
file as an image (and thus treat it as benign), but a user agent believes the
content to be HTML (and thus privileged to execute any scripts contained
therein), an attacker might be able to steal the user's authentication
credentials and mount other cross-site scripting attacks.
(Malicious servers, of course, can specify an arbitrary media type in the
<code>Content-Type</code> header field.)
In the absence of media type sniffing, this user-generated content would not
be interpreted as a high-privilege media type.
<p>
This document describes a content sniffing algorithm that carefully balances
the compatibility needs of user agent with the security constraints imposed
by existing web content.
The algorithm originated from research conducted by Adam Barth, Juan
Caballero, and Dawn Song, based on content sniffing algorithms present in
popular user agents, an extensive database of existing web content, and
metrics collected from implementations deployed to a sizable number of users.
<span data-anolis-ref>SECCONTSNIFF</span>
<p>
Whenever possible, user agents should not employ a content sniffing
algorithm.
However, if a user agent does employ a content sniffing algorithm, the user
agent should use the algorithm in this document; using a different content
sniffing algorithm could have unexpected security implications.
<h2>Conventions</h2>
<p>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119.
<span data-anolis-ref>RFC2119</span>
<p>
Requirements phrased in the imperative as part of algorithms (such as "strip
any leading space characters" or "return false and abort these steps") are to
be interpreted with the meaning of the key word ("MUST", "SHOULD", "MAY",
etc.) used in introducing the algorithm.
<p>
Conformance requirements phrased as algorithms or specific steps can be
implemented in any manner, so long as the end result is equivalent.
In particular, note that the algorithms defined in this specification are
intended to be easy to understand and are not intended to be performant.
<h2>Terminology</h2>
<p>
A <dfn>byte</dfn> is a <span data-anolis-spec=encoding>byte</span> as defined
in the Encoding Standard.
When helpful, a <span>byte</span> will be accompanied by information about
the ASCII code point it represents.
<span data-anolis-ref>ENCODING</span>
<span data-anolis-ref class=informative>ASCII</span>
<p>
A <dfn>binary data byte</dfn> is a <span>byte</span> in the range 0x00 to
0x08 (NUL to BS), the <span>byte</span> 0x0B (VT), a <span>byte</span> in the
range 0x0E to 0x1A (SO to SUB), or a <span>byte</span> in the range 0x1C to
0x1F (FS to US).
<p>
A <dfn>whitespace byte</dfn> (0xWS) is any of the following
<span title=byte>bytes</span>: 0x09 (HT), 0x0A (LF), 0x0C (FF), 0x0D (CR),
0x20 (SP).
<p>
A <dfn>tag-terminating byte</dfn> (0xTT) is any of the following
<span title=byte>bytes</span>: 0x20 (SP), 0x3E (<code title>></code>).
<p>
A <dfn>byte sequence</dfn> is a <span>sequence</span> of
<span title=byte>bytes</span>.
<p>
A <dfn>resource header</dfn> is the <span>byte sequence</span> at the
beginning of a <span>resource</span>, as determined by
<span title="read the resource header">reading the resource header</span>.
<p>
The <dfn>media type</dfn> of a resource is a technical hint about the use and
format of that resource.
<span data-anolis-ref class=informative>MIMETYPE</span>
<p>
A <dfn>valid media type</dfn> is a
<span data-anolis-spec=http>media-type</span>, as defined in HTTP/1.1 or its
successor, and is made up in part by a
<span data-anolis-spec=http>type</span> and a
<span data-anolis-spec=http>subtype</span>.
The <dfn>media type portion</dfn> of a <span>valid media type</span> is the
string represented by concatenating <span data-anolis-spec=http>type</span>,
the string "<code title>/</code>", and
<span data-anolis-spec=http>subtype</span>.
<span data-anolis-ref>HTTP</span>
<p class=note>
The <span>media type portion</span> of a <span>valid media type</span>
excludes all <span title=parameter data-anolis-spec=http>parameters</span>
and is case-insensitive.
<span data-anolis-ref>HTTP</span>
<p>
A <span>valid media type</span> is <dfn>supported by the user agent</dfn> if
the user agent has the capability to interpret a <span>resource</span> of
that <span>media type</span> and present it to the user.
<p>
An <dfn>image type</dfn> is any <span>valid media type</span> where
<span data-anolis-spec=http>type</span> is equal to
"<code title>image</code>"<!-- or the <span>media type portion</span> is
equal to one of the following:
<ul>
<li>
</ul>-->.
<p>
An <dfn>audio type</dfn> is any <span>valid media type</span> where
<span data-anolis-spec=http>type</span> is equal to
"<code title>audio</code>" or the <span>media type portion</span> is equal to
one of the following:
<ul>
<li>
<code title>application/ogg</code>
</ul>
<p>
A <dfn>video type</dfn> is any <span>valid media type</span> where
<span data-anolis-spec=http>type</span> is equal to
"<code title>video</code>" or the <span>media type portion</span> is equal to
one of the following:
<ul>
<li>
<code title>application/ogg</code>
</ul>
<p>
A <dfn>font type</dfn> is any <span>valid media type</span> where
<!--<span data-anolis-spec=http>type</span> is equal to
"<code title>font</code>" or--> the <span>media type portion</span> is equal
to one of the following:
<ul class=XXX>
<li>
</ul>
<p>
The <dfn>supplied media type</dfn> of a resource is the <span>valid media
type</span> of the resource as determined by the <span>supplied media type
detection algorithm</span>.
<p>
The <dfn>sniffed media type</dfn> of a resource is the <span>valid media
type</span> of the resource as determined by the <span>media type sniffing
algorithm</span>.
<p>
A <dfn>scriptable media type</dfn> is any of the following
<span title="valid media type">valid media types</span>:
<ul>
<li>
<code title>text/html</code>
<li>
<code title>text/xml</code>
<li>
<code title>application/pdf</code>
</ul>
<p>
A <dfn>byte pattern</dfn> is a <span>byte sequence</span> used as a template
to be matched against in the <span>pattern matching algorithm</span>.
<p>
A <dfn>pattern mask</dfn> is a <span>byte sequence</span> used to determine
the significance of <span title=byte>bytes</span> being compared against a
<span>byte pattern</span> in the <span>pattern matching algorithm</span>.
<p class=note>
In a <span>pattern mask</span>, 0xFF indicates the <span>byte</span> is
strictly significant, 0xDF indicates that the <span>byte</span> is
significant in an ASCII case-insensitive way, and 0x00 indicates that the
<span>byte</span> is not significant.
<h2>The supplied media type</h2>
<p>
The <span>supplied media type</span> of a resource is provided to the user
agent by an external source associated with that resource.
The method of obtaining this information varies depending upon how the
resource is retrieved.
<p>
The <span>supplied media type detection algorithm</span> makes use of the
<dfn>has-content-type flag</dfn>, which must be unset by default and must
only be set from within the <span>supplied media type detection
algorithm</span>.
<p>
To determine the <span>supplied media type</span> of a resource, user agents
must use the following <dfn>supplied media type detection algorithm</dfn>:
<ol>
<li>
Let <var>official-type</var> be null.
<li>
If the resource is retrieved via HTTP and one or more
<code>Content-Type</code> headers are associated with the resource, set
<var>official-type</var> to the value associated with the last such
<code>Content-Type</code> header and set the <span>has-content-type
flag</span>.
<span data-anolis-ref=http>HTTP</span>
<p class=note>
File extensions are not used to determine the <span>supplied media
type</span> of a resource retrieved via HTTP because they are unreliable
and easily spoofed.
<li>
If the resource is retrieved directly from the file system, set
<var>official-type</var> to the <span>media type</span> provided by the
file system.
<li>
If the resource is retrieved via another protocol (such as FTP), set
<var>official-type</var> to the <span>media type</span> as determined by
that protocol, if any.
<span data-anolis-ref class=informative>FTP</span>
<li>
If <var>official-type</var> is not a <span>valid media type</span>, set
<var>official-type</var> to null.
<li>
The <span>supplied media type</span> is <var>official-type</var>.
</ol>
<h2>Reading the resource header</h2>
<p>
To <dfn>read the resource header</dfn>, perform the following steps:
<ol>
<li>
Read <span title=byte>bytes</span> of the resource into <var>buffer</var>
until one of the following conditions is met:
<ul>
<li>
the end of the resource is reached.
<li>
the length of <var>buffer</var> is greater than or equal to 512
<span title=byte>bytes</span>.
<li>
a reasonable amount of time has elapsed, as determined by the user
agent.
</ul>
<p class=note>
If the length of <var>buffer</var> is greater than or equal to 512
<span title=byte>bytes</span>, the <span>media type sniffing
algorithm</span> will be deterministic for the majority of cases.
However, certain factors (such as a slow connection) may prevent the
user agent from reading 512 <span title=byte>bytes</span> in a
reasonable amount of time.
<li>
The <span>resource header</span> is <var>buffer</var>.
</ol>
<p class=note>
The <span>resource header</span> need only be determined once per
<span>resource</span>.
<h2>The sniffed media type</h2>
<p>
The following flags are used in the <span>media type sniffing
algorithm</span> and must be unset by default:
<var class=flag>sniff-all</var>, <var class=flag>sniff-unknown</var>,
<var class=flag>sniff-text-or-binary</var>,
<var class=flag>sniff-feed-or-html</var>, <var class=flag>sniff-images</var>,
<var class=flag>sniff-audio</var>, <var class=flag>sniff-video</var>,
<var class=flag>sniff-fonts</var>.
User agents may explicitly set one or more of these flags when calling the
<span>media type sniffing algorithm</span>.
<p>
To determine the <span>sniffed media type</span> of a resource, user agents
must use the following <dfn>media type sniffing algorithm</dfn>:
<ol>
<li>
If the <span>supplied media type</span> is not null and the <span>media
type portion</span> of the <span>supplied media type</span> ends in
"<code title>+xml</code>" or is equal to "<code title>text/xml</code>" or
"<code title>application/xml</code>", the <span>sniffed media type</span>
is the <span>supplied media type</span>.
Abort these steps.
<li>
If the <var class=flag>sniff-all</var> flag is set, set the
<var class=flag>sniff-unknown</var>,
<var class=flag>sniff-text-or-binary</var>,
<var class=flag>sniff-feed-or-html</var>,
<var class=flag>sniff-images</var>, <var class=flag>sniff-audio</var>,
<var class=flag>sniff-video</var>, and <var class=flag>sniff-fonts</var>
flags.
<li>
If the <var class=flag>sniff-unknown</var> flag is set and the
<span>supplied media type</span> is null or if the
<var class=flag>sniff-unknown</var> flag is set and the <span>supplied
media type</span> is not null and the <span>media type portion</span> of
the <span>supplied media type</span> is equal to
"<code title>unknown/unknown</code>",
"<code title>application/unknown</code>", or "<code title>*/*</code>",
execute the <span>rules for identifying an unknown media type</span>.
<li>
If the <var class=flag>sniff-text-or-binary</var> flag is set and the
<span>has-content-type flag</span> is set and the <span>supplied media
type</span> is <strong>exactly</strong> equal to one of the values in the
following table, execute the <span>rules for distinguishing if a resource
is text or binary</span>:
<table>
<thead>
<tr>
<th>Bytes in Hexadecimal</th>
<th>Bytes in ASCII</th>
</tr>
</thead>
<tbody>
<tr>
<td>
74 65 78 74 2F 70 6C 61 69 6E
</td>
<td>
<code title>text/plain</code>
</td>
</tr>
<tr>
<td>
74 65 78 74 2F 70 6C 61 69 6E<br>
3B 20 63 68 61 72 73 65 74 3D<br>
49 53 4F 2D 38 38 35 39 2D 31
</td>
<td>
<code title>text/plain; charset=ISO-8859-1</code>
</td>
</tr>
<tr>
<td>
74 65 78 74 2F 70 6C 61 69 6E<br>
3B 20 63 68 61 72 73 65 74 3D<br>
69 73 6F 2D 38 38 35 39 2D 31
</td>
<td>
<code title>text/plain; charset=iso-8859-1</code>
</td>
</tr>
<tr>
<td>
74 65 78 74 2F 70 6C 61 69 6E<br>
3B 20 63 68 61 72 73 65 74 3D<br>
55 54 46 2D 38
</td>
<td>
<code title>text/plain; charset=UTF-8</code>
</td>
</tr>
</tbody>
</table>
<p class=note>
The <span>media type sniffing algorithm</span> detects these exact
<span>byte</span> sequences because some older installations of Apache
contain a bug that causes them to supply one of these Content-Type headers
when serving files with unrecognized file extensions.
<li>
<!-- XXX: Why are we checking to see if the image type is supported by the
user agent if we're just going to sniff it again anyway? -->
If the <var class=flag>sniff-images</var> flag is set and the
<span>supplied media type</span> is an <span>image type</span>
<span>supported by the user agent</span>, execute the <span>rules for
sniffing images specifically</span>.
<li>
<!-- XXX: Why are we checking to see if the audio type is supported by the
user agent if we're just going to sniff it again anyway? -->
If the <var class=flag>sniff-audio</var> flag is set and the <span>supplied
media type</span> is an <span>audio type</span> <span>supported by the user
agent</span>, execute the <span>rules for sniffing audio
specifically</span>.
<li>
<!-- XXX: Why are we checking to see if the video type is supported by the
user agent if we're just going to sniff it again anyway? -->
If the <var class=flag>sniff-video</var> flag is set and the <span>supplied
media type</span> is a <span>video type</span> <span>supported by the user
agent</span>, execute the <span>rules for sniffing videos
specifically</span>.
<li>
<!-- XXX: Why are we checking to see if the font type is supported by the
user agent if we're just going to sniff it again anyway? -->
If the <var class=flag>sniff-fonts</var> flag is set and the <span>supplied
media type</span> is a <span>font type</span> <span>supported by the user
agent</span>, execute the <span>rules for sniffing fonts
specifically</span>.
<li>
If the <var class=flag>sniff-feed-or-html</var> flag is set and the
<span>supplied media type</span> is not null and the <span>media type
portion</span> of the <span>supplied media type</span> is equal to
"<code title>text/html</code>", execute the <span>rules for distinguishing
if a resource is a feed or HTML</span>.
<li>
The <span>sniffed media type</span> is the <span>supplied media
type</span>.
</ol>
<h3>Text or binary media type</h3>
<p>
This section defines the <dfn id=rules-for-text-or-binary>rules for
distinguishing if a resource is text or binary</dfn>:
<ol>
<li>
Let <var>length</var> be the number of <span title=byte>bytes</span> in the
<span>resource header</span>.
<li>
If <var>length</var> is greater than or equal to 2 and the first 2 bytes of
the <span>resource header</span> are equal to 0xFE 0xFF (UTF-16BE BOM) or
0xFF 0xFE (UTF-16LE BOM), the <span>sniffed media type</span> is
"<code title>text/plain</code>".
Abort these steps.
<li>
If <var>length</var> is greater than or equal to 3 and the first 3 bytes of
the <span>resource header</span> are equal to 0xEF 0xBB 0xBF (UTF-8 BOM),
the <span>sniffed media type</span> is "<code title>text/plain</code>".
Abort these steps.
<li>
If the <span>resource header</span> contains no
<span title="binary data byte">binary data bytes</span>, the <span>sniffed
media type</span> is "<code title>text/plain</code>".
Abort these steps.
<li>
Execute the <span>rules for identifying an unknown media type</span> with
the <var>sniff-scriptable</var> flag unset.
<p class=warning>
It is critical that the <span>rules for distinguishing if a resource is
text or binary</span> never determine the <span>sniffed media type</span>
to be a <span>scriptable media type</span>, as this could allow a privilege
escalation attack.
</ol>
<h3>Unknown media type</h3>
<p>
The <span>rules for identifying an unknown media type</span> use the
<var>sniff-scriptable</var> flag, which must be unset by default.
User agents may explicitly set the <var>sniff-scriptable</var> flag when
calling the <span>rules for identifying an unknown media type</span>.
<p>
To determine the <span>sniffed media type</span> of a <span>resource</span>
with an unknown <span>media type</span>, execute the following <dfn>rules for
identifying an unknown media type</dfn>:
<ol>
<li>
Let <var>length</var> be the number of <span title=byte>bytes</span> in the
<span>resource header</span>.
<li>
If the <var>sniff-scriptable</var> flag is set, execute the following steps
for each row in the following table:
<ol>
<li>
Let <var>pattern-matched</var> be the result of executing the
<span>pattern matching algorithm</span> with the following parameters:
<ul>
<li>
Let the <span>byte sequence</span> to be matched be the <span>resource
header</span>.
<li>
Let the <span>byte pattern</span> to be matched against be the value in
the first column of the current row.
<li>
Let the <span>pattern mask</span> be the value in the second column of
the current row.
<li>
Let the leading <span title=byte>bytes</span> to be ignored be the
value in the third column of the current row.
</ul>
<li>
If <var>pattern-matched</var> is true, the <span>sniffed media type</span>
is the value in the fourth column of the current row.
Abort these steps.
</ol>
<table>
<thead>
<tr>
<th>
<span>Byte Pattern</span>
</th>
<th>
<span>Pattern Mask</span>
</th>
<th>
Leading <span title=byte>Bytes</span> to Be Ignored
</th>
<th>
<span>Sniffed Media Type</span>
</th>
<th>
Note
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
3C 21 44 4F 43 54 59 50 45 20 48 54 4D 4C TT
</td>
<td>
FF FF DF DF DF DF DF DF DF FF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><!DOCTYPE HTML</code>"
followed by a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 48 54 4D 4C TT
</td>
<td>
FF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><HTML</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 48 45 41 44 TT
</td>
<td>
FF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><HEAD</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 53 43 52 49 50 54 TT
</td>
<td>
FF DF DF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><SCRIPT</code>" followed by
a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 49 46 52 41 4D 45 TT
</td>
<td>
FF DF DF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><IFRAME</code>" followed by
a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 48 31 TT
</td>
<td>
FF DF FF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><H1</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 44 49 56 TT
</td>
<td>
FF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><DIV</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 46 4F 4E 54 TT
</td>
<td>
FF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><FONT</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 54 41 42 4C 45 TT
</td>
<td>
FF DF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><TABLE</code>" followed by
a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 41 TT
</td>
<td>
FF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><A</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 53 54 59 4C 45 TT
</td>
<td>
FF DF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><STYLE</code>" followed by
a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 54 49 54 4C 45 TT
</td>
<td>
FF DF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><TITLE</code>" followed by
a <span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 42 TT
</td>
<td>
FF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><B</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 42 4F 44 59 TT
</td>
<td>
FF DF DF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><BODY</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 42 52 TT
</td>
<td>
FF DF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><BR</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 50 TT
</td>
<td>
FF DF FF
</td>
<td>
<span title="whitespace byte">Whitespace bytes</span>.
</td>
<td>
<code title>text/html</code>
</td>
<td>
The case-insensitive string "<code title><P</code>" followed by a
<span>tag-terminating byte</span>.
</td>
</tr>
<tr>
<td>
3C 21 2D 2D TT
</td>
<td>
FF FF FF FF FF
</td>