Skip to content

Commit b5bda65

Browse files
committed
Add configs for text files (.txt)
Prevent Apache from sending the HTTP headers intended only for HTML documents when serving text files.
1 parent 0bb12c8 commit b5bda65

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### HEAD
22

3+
* Add configs for text files (`.txt`).
34
* Compress WebVTT files (`.vtt`).
45
* Reintroduce the `filename extension` to `content type` mappings for `ico`
56
and `svg` ([#28](https://github.com/h5bp/server-configs-apache/issues/28)).

src/.htaccess

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ Options -MultiViews
8787

8888
<IfModule mod_headers.c>
8989
Header set X-UA-Compatible "IE=edge"
90-
# `mod_headers` cannot match based on the content-type, however, this
91-
# header should be send only for HTML pages and not for the other resources
92-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
90+
# `mod_headers` cannot match based on the content-type, however, this header
91+
# should be send only for HTML documents and not for the other resources
92+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
9393
Header unset X-UA-Compatible
9494
</FilesMatch>
9595
</IfModule>
@@ -289,7 +289,7 @@ AddDefaultCharset utf-8
289289

290290
# <IfModule mod_headers.c>
291291
# Header set X-Frame-Options "DENY"
292-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
292+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
293293
# Header unset X-Frame-Options
294294
# </FilesMatch>
295295
# </IfModule>
@@ -314,7 +314,7 @@ AddDefaultCharset utf-8
314314

315315
# <IfModule mod_headers.c>
316316
# Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
317-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
317+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
318318
# Header unset Content-Security-Policy
319319
# </FilesMatch>
320320
# </IfModule>
@@ -430,7 +430,7 @@ AddDefaultCharset utf-8
430430
# <IfModule mod_headers.c>
431431
# # (1) (2)
432432
# Header set X-XSS-Protection "1; mode=block"
433-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
433+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
434434
# Header unset X-XSS-Protection
435435
# </FilesMatch>
436436
# </IfModule>

test/fixtures/content/.htaccess

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ ErrorDocument 404 /404.html
8787

8888
<IfModule mod_headers.c>
8989
Header set X-UA-Compatible "IE=edge"
90-
# `mod_headers` cannot match based on the content-type, however, this
91-
# header should be send only for HTML pages and not for the other resources
92-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
90+
# `mod_headers` cannot match based on the content-type, however, this header
91+
# should be send only for HTML documents and not for the other resources
92+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
9393
Header unset X-UA-Compatible
9494
</FilesMatch>
9595
</IfModule>
@@ -289,7 +289,7 @@ AddDefaultCharset utf-8
289289

290290
<IfModule mod_headers.c>
291291
Header set X-Frame-Options "DENY"
292-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
292+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
293293
Header unset X-Frame-Options
294294
</FilesMatch>
295295
</IfModule>
@@ -314,7 +314,7 @@ AddDefaultCharset utf-8
314314

315315
<IfModule mod_headers.c>
316316
Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
317-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
317+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
318318
Header unset Content-Security-Policy
319319
</FilesMatch>
320320
</IfModule>
@@ -430,7 +430,7 @@ AddDefaultCharset utf-8
430430
<IfModule mod_headers.c>
431431
# (1) (2)
432432
Header set X-XSS-Protection "1; mode=block"
433-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
433+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
434434
Header unset X-XSS-Protection
435435
</FilesMatch>
436436
</IfModule>

test/test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,16 @@ var tests = [
385385
'test.ttf': {
386386
headers: generateHeaders({
387387
'access-control-allow-origin': '*',
388-
'content-security-policy': undefined,
389388
'content-type': 'application/x-font-ttf'
390389
})
391390
},
392391

392+
'test.txt': {
393+
headers: generateHeaders({
394+
'content-type': 'text/plain; charset=utf-8'
395+
})
396+
},
397+
393398
'test.vcf': {
394399
headers: generateHeaders({
395400
'content-encoding': undefined,

0 commit comments

Comments
 (0)