forked from whatwg/mimesniff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Overview.src.html
3162 lines (2609 loc) · 85.1 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: 0.6em;
vertical-align: super;
text-transform: uppercase;
}
a.bug-link {
display: none;
}
}
</style>
<link rel="stylesheet" href="https://www.whatwg.org/style/specification" />
<link rel="icon" href="https://resources.whatwg.org/logo-mime.png" type="image/png" />
<link rel="icon" href="https://resources.whatwg.org/logo-mime.svg" type="image/svg+xml" />
<div class="head">
<p><a class="logo" href="https://www.whatwg.org/"><img src="https://resources.whatwg.org/logo-mime.svg" width="101" height="101" alt="WHATWG" /></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="https://mimesniff.spec.whatwg.org/">https://mimesniff.spec.whatwg.org/</a>
<dt>Participate:
<dd>
Send feedback to
<a href="https://www.whatwg.org/mailing-list">whatwg@whatwg.org</a>
(<a href="https://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="https://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="https://resources.whatwg.org/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">Table of contents</h2>
<!--toc-->
<h2>Introduction</h2>
<p>
The HTTP <code>Content-Type</code> header field is intended to indicate the
MIME type of an HTTP response.
However, many HTTP servers supply a <code>Content-Type</code> header field
value 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 in order to determine the effective MIME type of the response.
<p>
Without a clear specification for how to "sniff" the MIME 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 MIME 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 MIME 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 MIME type in the
<code>Content-Type</code> header field.)
<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 class=informative>SECCONTSNIFF</span>
<h2>Conformance requirements</h2>
<p>
The keywords "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.
For readability, these keywords will generally not appear in all uppercase
letters.
<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 keyword 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> (abbreviated
<abbr title="whitespace byte">0xWS</abbr>) is any one 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> (abbreviated
<abbr title="tag-terminating byte">0xTT</abbr>) is any one of the following
<span title=byte>bytes</span>: 0x20 (SP), 0x3E ("<code title>></code>").
<p>
A <dfn>byte sequence</dfn> is a list of one or more
<span title=byte>bytes</span>, such that the position of the first
<span>byte</span> and the position of the last <span>byte</span> are
unambiguously identifiable.
<p>
<dfn title="converted to ASCII lowercase">Converting a string to ASCII
lowercase</dfn> is accomplished by
<span data-anolis-spec=html title="converted to ASCII lowercase">converting a
string to ASCII lowercase</span> as defined in the HTML Standard.
<span data-anolis-ref>HTML</span>
<h2>Understanding MIME types</h2>
<p>
The <dfn>MIME type</dfn> of a <span>resource</span> is a technical hint
about the use and format of that <span>resource</span>.
<span data-anolis-ref class=informative>MIMETYPE</span>
<p>
A <dfn>parsable MIME type</dfn> is a <span>MIME type</span> for which the
<span>parse a MIME type</span> algorithm does not return undefined.
Every <span>parsable MIME type</span> has a corresponding <dfn>parsed MIME
type</dfn>, which is the result of
<span title="parse a MIME type">parsing</span> the <span>parsable MIME
type</span>.
A <span>parsed MIME type</span> is made up of a <dfn>type</dfn>, a
<dfn>subtype</dfn>, and a dictionary of <dfn>parameters</dfn>.
<p>
A <dfn>serialized MIME type</dfn> is the result of
<span title="serialize a MIME type">serializing</span> a <span>parsed MIME
type</span>.
<p>
The <dfn>MIME type portion</dfn> of a <span>parsable MIME type</span> is the
result of <span title="serialize a MIME type">serializing</span> the
<span>type</span> and <span>subtype</span> of its <span>parsed MIME
type</span> with null <span>parameters</span>.
<p class=note>
The <span>MIME type portion</span> of a <span>parsable MIME type</span>
excludes any and all <span>parameters</span>.
<p>
A <span>parsable MIME 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>MIME type</span> and present it to the user.
<h3>Parsing a MIME type</h3>
<p>
To <dfn>parse a MIME type</dfn>, the user agent must execute the following
steps:
<ol>
<li>
Let <var>sequence</var> be the <span>byte sequence</span> of the <span>MIME
type</span>, where <var>sequence</var>[<var>s</var>] is <span>byte</span>
<var>s</var> in <var>sequence</var> and <var>sequence</var>[0] is the first
<span>byte</span> in <var>sequence</var>.
<li>
If the number of <span title=byte>bytes</span> in <var>sequence</var> is
less than 1, return undefined.
<li>
Initialize <var>s</var> to 0.
<li>
Initialize <var>type</var> and <var>subtype</var> to the empty string
("<code title></code>").
<li>
Initialize <var>parameters</var> to the empty dictionary ({}).
<li>
While <var>sequence</var>[<var>s</var>] is a <span>whitespace
character</span>, continuously execute the following steps:
<ol>
<li>
Increment <var>s</var> by 1.
</ol>
<li class=XXX>
Initialize <var>t</var> to 0.
<li>
While <var>sequence</var>[<var>s</var>] is not equal to the U+002F SOLIDUS
character ("<code title>/</code>"), continuously execute the
following steps:
<ol>
<li class=XXX>
If <var>t</var> is greater than 127, return undefined.
<li>
If <var>sequence</var>[<var>s</var>] is undefined, return undefined.
<li>
Append <var>sequence</var>[<var>s</var>], <span>converted to ASCII
lowercase</span>, to <var>type</var>.
<li>
Increment <var>s</var> <span class=XXX>and <var>t</var></span> by 1.
</ol>
<li>
Increment <var>s</var> by 1.
<li class=XXX>
Initialize <var>u</var> to 0.
<li>
While <var>sequence</var>[<var>s</var>] is not a <span>whitespace
character</span> and is not equal to the U+003B SEMICOLON character
("<code title>;</code>"), continuously execute the following steps:
<ol>
<li class=XXX>
If <var>u</var> is greater than 127, return undefined.
<li>
If <var>sequence</var>[<var>s</var>] is undefined, return
<var>type</var>, <var>subtype</var>, and <var>parameters</var>.
<li>
Append <var>sequence</var>[<var>s</var>], <span>converted to ASCII
lowercase</span>, to <var>subtype</var>.
<li>
Increment <var>s</var> <span class=XXX>and <var>u</var></span> by 1.
</ol>
<li>
Enter loop <var>L</var>:
<ol>
<li>
Enter loop <var>M</var>:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined or is equal to the
U+003B SEMICOLON character ("<code>;</code>"), exit loop
<var>M</var>.
<li>
While <var>sequence</var>[<var>s</var>] is a <span>whitespace
character</span>, continuously execute the following steps:
<ol>
<li>
Increment <var>s</var> by 1.
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+0022 QUOTATION
MARK character ("<code title>"</code>"), execute the following
steps:
<ol>
<li>
Increment <var>s</var> by 1.
<li>
Enter loop <var>N</var>:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined or is equal to
the U+0022 QUOTATION MARK character
("<code title>"</code>"), execute the following steps:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+0022
QUOTATION MARK character ("<code title>"</code>"),
increment <var>s</var> by 1.
<li>
Exit loop <var>N</var>.
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+005C
REVERSE SOLIDUS character ("<code title>\</code>") and
<var>sequence</var>[<var>s</var> + 1] is not undefined, increment
<var>s</var> by 1.
<li>
Increment <var>s</var> by 1.
</ol>
</ol>
Otherwise, enter loop <var>N</var>:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined or is a
<span>whitespace character</span> or is equal to the U+003B
SEMICOLON character ("<code>;</code>"), exit loop
<var>N</var>.
<li>
Increment <var>s</var> by 1.
</ol>
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined, return
<var>type</var>, <var>subtype</var>, and <var>parameters</var>.
<li>
Increment <var>s</var> by 1.
<li>
While <var>sequence</var>[<var>s</var>] is a <span>whitespace
character</span>, continuously execute the following steps:
<ol>
<li>
Increment <var>s</var> by 1.
</ol>
<li>
Initialize <var>name</var> and <var>extra</var> to the empty string
("<code title></code>").
<li class=XXX>
Initialize <var>p</var> to 0.
<li>
Enter loop <var>M</var>:
<ol>
<li class=XXX>
Append <var>extra</var> to <var>name</var>.
<li>
While <var>sequence</var>[<var>s</var>] is not a <span>whitespace
character</span> and is not equal to the U+003D EQUALS SIGN character
("<code title>=</code>"), continuously execute the following
steps:
<ol>
<li class=XXX>
If <var>p</var> is greater than 127, return undefined.
<li>
If <var>sequence</var>[<var>s</var>] is undefined, execute the
following steps:
<ol>
<li>
If <var>name</var> is not equal to the empty string
("<code title></code>") and <var>parameters</var>[<var>name</var>]
is undefined, set <var>parameters</var>[<var>name</var>] to null.
<li>
Return <var>type</var>, <var>subtype</var>, and
<var>parameters</var>.
</ol>
<li>
Append <var>sequence</var>[<var>s</var>], <span>converted to ASCII
lowercase</span>, to <var>name</var>.
<li>
Increment <var>s</var> <span class=XXX>and <var>p</var></span> by 1.
</ol>
<li class=XXX>
While <var>sequence</var>[<var>s</var>] is a <span>whitespace
character</span>, continuously execute the following steps:
<ol>
<li>
Append <var>sequence</var>[<var>s</var>] to <var>extra</var>.
<li>
Increment <var>s</var> <span class=XXX>and <var>p</var></span> by 1.
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+003D EQUALS
SIGN character ("<code title>=</code>"), exit loop
<var>M</var>.
</ol>
<li>
Increment <var>s</var> by 1.
<li>
Initialize <var>parameters</var>[<var>name</var>] to null.
<li>
While <var>sequence</var>[<var>s</var>] is a <span>whitespace
character</span>, continuously execute the following steps:
<ol>
<li>
Increment <var>s</var> by 1.
</ol>
<li>
Initialize <var>value</var> to the empty string ("<code title></code>").
<li>
If <var>sequence</var>[<var>s</var>] is undefined, execute the following
steps:
<ol>
<li>
Set <var>parameters</var>[<var>name</var>] to <var>value</var>.
<li>
Return <var>type</var>, <var>subtype</var>, and <var>parameters</var>.
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+0022 QUOTATION
MARK character ("<code title>"</code>"), execute the following
steps:
<ol>
<li>
Increment <var>s</var> by 1.
<li>
Enter loop <var>M</var>:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined or is equal to the
U+0022 QUOTATION MARK character ("<code title>"</code>"),
execute the following steps:
<ol>
<li>
Set <var>parameters</var>[<var>name</var>] to <var>value</var>.
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+0022
QUOTATION MARK character ("<code title>"</code>"),
increment <var>s</var> by 1.
<li>
Exit loop <var>M</var>.
</ol>
<li>
If <var>sequence</var>[<var>s</var>] is equal to the U+005C REVERSE
SOLIDUS character ("<code title>\</code>") and
<var>sequence</var>[<var>s</var> + 1] is not undefined, increment
<var>s</var> by 1.
<li>
Append <var>sequence</var>[<var>s</var>] to <var>value</var>.
<li>
Increment <var>s</var> by 1.
</ol>
</ol>
Otherwise, enter loop <var>M</var>:
<ol>
<li>
If <var>sequence</var>[<var>s</var>] is undefined or is a
<span>whitespace character</span> or is equal to the U+003B SEMICOLON
character ("<code>;</code>"), execute the following steps:
<ol>
<li>
Set <var>parameters</var>[<var>name</var>] to <var>value</var>.
<li>
Exit loop <var>M</var>.
</ol>
<li>
Append <var>sequence</var>[<var>s</var>] to <var>value</var>.
<li>
Increment <var>s</var> by 1.
</ol>
</ol>
</ol>
<p class=note>
The <span>parse a MIME type</span> algorithm is intended to be executed after
any protocol-specific syntax within the <span>MIME type</span> has been
handled.
<h3>Serializing a MIME type</h3>
<p>
To <dfn>serialize a MIME type</dfn>, given a <var>type</var>, a
<var>subtype</var>, and a dictionary of <var>parameters</var>, execute the
following steps:
<ol>
<li>
If <var>type</var> is undefined, is null, is equal to the empty string
("<code title></code>"), or <span class=XXX>has a length greater than
127</span>, return undefined.
<li>
If <var>subtype</var> is undefined, is null, or <span class=XXX>has a
length greater than 127</span>, return undefined.
<li>
Let <var>serialization</var> be the concatenation of <var>type</var>, the
U+002F SOLIDUS <span>character</span> ("<code title>/</code>"), and
<var>subtype</var>.
<li>
If <var>parameters</var> is undefined or is null, return
<var>serialization</var>.
<li>
Let <var>names</var> be a list of the keys in <var>parameters</var>,
<span class=XXX>sorted <span title="ASCII case-insensitive">ASCII
case-insensitively</span> in ascending alphabetical order</span>.
<li class=XXX>
Should this special-case the "<code>charset</code>" or
"<code>codecs</code>" parameters first?
<li>
For each item <var>name</var> in <var>names</var>, execute the following
steps:
<ol>
<li class=XXX>
If <var>name</var> has a length greater than 127, return undefined.
<li>
If <var>parameters</var>[<var>name</var>] is not null, execute the
following steps:
<ol>
<li>
Append the U+003B SEMICOLON <span>character</span>
("<code title>;</code>") to <var>serialization</var>.
<li>
Append <var>name</var>, <span>converted to ASCII lowercase</span>, to
<var>serialization</var>.
<li>
Append the U+003D EQUALS SIGN <span>character</span>
("<code title>=</code>") to <var>serialization</var>.
<li>
Append the U+0022 QUOTATION MARK <span>character</span>
("<code title>"</code>") to <var>serialization</var>.
<li>
For each <span>character</span> <var>char</var> in
<var>parameters</var>[<var>name</var>], execute the following steps:
<ol>
<li>
If <var>char</var> is equal to the U+0022 QUOTATION MARK
<span>character</span> ("<code title>"</code>") or to the
U+005C REVERSE SOLIDUS <span>character</span>
("<code title>\</code>"), append the U+005C REVERSE SOLIDUS
<span>character</span> ("<code title>\</code>") to
<var>serialization</var>.
<li>
Append <var>char</var> to <var>serialization</var>.
</ol>
<li>
Append the U+0022 QUOTATION MARK <span>character</span>
("<code title>"</code>") to <var>serialization</var>.
<li>
Remove <var>name</var> from <var>names</var>.
</ol>
</ol>
<li>
For each item <var>name</var> in <var>names</var>, execute the following
steps:
<ol>
<li>
Append the U+003B SEMICOLON <span>character</span>
("<code title>;</code>") to <var>serialization</var>.
<li>
Append <var>name</var>, <span>converted to ASCII lowercase</span>, to
<var>serialization</var>.
</ol>
<li class=XXX>
Should this special-case the "<code>base64</code>" boolean parameter last?
<li>
Return <var>serialization</var>.
</ol>
<h3>MIME type groups</h3>
<p>
An <dfn>image type</dfn> is any <span>parsable MIME type</span> where
<span>type</span> is equal to "<code title>image</code>"<!-- or the
<span>MIME type portion</span> is equal to one of the following:
<ul>
<li>
</ul>-->.
<p>
An <dfn>audio or video type</dfn> is any <span>parsable MIME type</span>
where <span>type</span> is equal to "<code title>audio</code>" or
"<code title>video</code>" or where the <span>MIME 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>parsable MIME type</span> where
<!--<span>type</span> is equal to "<code title>font</code>" or--> the
<span>MIME type portion</span> is equal to one of the following:
<ul class=XXX>
<li>
<code title>application/font-ttf</code>
<li>
<code title>application/font-cff</code>
<li>
<code title>application/font-off</code>
<li>
<code title>application/font-sfnt</code>
<li>
<code title>application/vnd.ms-opentype</code>
<li>
<code title>application/font-woff</code>
<li>
<code title>application/vnd.ms-fontobject</code>
</ul>
<p>
A <dfn>ZIP-based type</dfn> is any <span>parsable MIME type</span> where the
<span>subtype</span> ends in "<code title>+zip</code>" or the <span>MIME type
portion</span> is equal to one of the following:
<ul class=XXX>
<li>
<code title>application/zip</code>
</ul>
<p>
An <dfn>archive type</dfn> is any <span>parsable MIME type</span> where
<!--<span>type</span> is equal to "<code title>archive</code>" or--> the
<span>MIME type portion</span> is equal to one of the following:
<ul>
<li>
<code title>application/x-rar-compressed</code>
<li>
<code title>application/zip</code>
<li>
<code title>application/x-gzip</code>
</ul>
<p>
An <dfn>XML type</dfn> is any <span>parsable MIME type</span> where the
<span>subtype</span> ends in "<code title>+xml</code>" or the <span>MIME type
portion</span> is equal to "<code title>text/xml</code>" or
"<code title>application/xml</code>".
<span data-anolis-ref class=informative>RFC3023</span>
<p>
A <dfn>scriptable MIME type</dfn> is an <span>XML type</span> or any
<span>parsable MIME type</span> where the <span>MIME type portion</span> is
equal to one of the following:
<ul>
<li>
<code title>text/html</code>
<li>
<code title>application/pdf</code>
</ul>
<h2>Handling a resource</h2>
<p class=XXX>
A <dfn>resource</dfn> is ….
<p>
For each <span>resource</span> it handles, the user agent must keep track of
the following associated metadata:
<ul>
<li>
A <dfn>supplied MIME type</dfn>, the <span>MIME type</span> determined by
the <span>supplied MIME type detection algorithm</span>.
<li>
A <dfn>check-for-apache-bug flag</dfn>, which defaults to unset.
<li>
A <dfn>no-sniff flag</dfn>, which defaults to set if the user agent does
not wish to perform sniffing on the <span>resource</span> and unset
otherwise.
<p class=note>
The user agent can choose to use outside information, such as previous
experience with a site, to determine whether to opt out of sniffing for a
particular <span>resource</span>. The user agent can also choose to opt
out of sniffing for all <span title=resource>resources</span>. However,
opting out of sniffing does not exempt the user agent from using the
<span>MIME type sniffing algorithm</span>.
<li>
A <dfn>sniffed MIME type</dfn>, the <span>parsable MIME type</span>
determined by the <span>MIME type sniffing algorithm</span>.
</ul>
<h3>Interpreting the resource metadata</h3>
<p>
The <span>supplied MIME type</span> of a <span>resource</span> is provided
to the user agent by an external source associated with that
<span>resource</span>.
The method of obtaining this information varies depending upon how the
<span>resource</span> is retrieved.
<p>
To determine the <span>supplied MIME type</span> of a <span>resource</span>,
user agents must use the following <dfn>supplied MIME type detection
algorithm</dfn>:
<ol>
<li>
Let <var>supplied-type</var> be null.
<li>
If the <span>resource</span> is retrieved via HTTP, execute the following
steps:
<ol>
<li>
If one or more <code>Content-Type</code> headers are associated with the
<span>resource</span>, execute the following steps:
<ol>
<li>
Set <var>supplied-type</var> to the value of the last
<code>Content-Type</code> header associated with the
<span>resource</span>.
<p class=note>
File extensions are not used to determine the <span>supplied MIME
type</span> of a <span>resource</span> retrieved via HTTP because they are
unreliable and easily spoofed.
<li>
Set the <span>check-for-apache-bug flag</span> if
<var>supplied-type</var> is <strong>exactly</strong> equal to one of
the values in the following table:
<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>supplied MIME type detection algorithm</span> detects these
exact <span>byte</span> sequences because some older installations of
Apache contain
<a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=13986">a
bug</a> that causes them to supply one of these Content-Type headers
when serving files with unrecognized <span title="MIME type">MIME
types</span>.
</ol>
<li>
If one or more <code>X-Content-Type-Options</code> headers are associated
with the <span>resource</span> and any such
<code>X-Content-Type-Options</code> header has a value equal to
"<code title>nosniff</code>", set the <span>no-sniff flag</span>.
</ol>
<span data-anolis-ref=http>HTTP</span>
<li>
If the <span>resource</span> is retrieved directly from the file system,
set <var>supplied-type</var> to the <span>MIME type</span> provided by the
file system.
<li>
If the <span>resource</span> is retrieved via another protocol (such as
FTP), set <var>supplied-type</var> to the <span>MIME type</span> as
determined by that protocol, if any.
<span data-anolis-ref class=informative>FTP</span>
<li>
If <var>supplied-type</var> is not a <span>parsable MIME type</span>, the
<span>supplied MIME type</span> is undefined.
Abort these steps.
<li>
The <span>supplied MIME type</span> is <var>supplied-type</var>.
</ol>
<h3>Reading the resource header</h3>
<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>
To <dfn>read the resource header</dfn>, perform the following steps:
<ol>
<li>
Let <var>buffer</var> be a <span>byte sequence</span>.