Skip to content

Commit 9d4a8b8

Browse files
authored
Merge pull request #635 from aledbf/feature-632
Allow configuration of features underscores_in_headers and ignore_invalid_headers
2 parents 203171e + 12d4aad commit 9d4a8b8

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

controllers/nginx/configuration.md

+5
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Example usage: `custom-http-errors: 404,415`
262262

263263
**enable-sticky-sessions:** Enables sticky sessions using cookies. This is provided by [nginx-sticky-module-ng](https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng) module.
264264

265+
**enable-underscores-in-headers:** Enables underscores in header names. This is disabled by default.
265266

266267
**enable-vts-status:** Allows the replacement of the default status page with a third party module named [nginx-module-vts](https://github.com/vozlt/nginx-module-vts).
267268

@@ -287,6 +288,8 @@ https://blog.qualys.com/securitylabs/2016/03/28/the-importance-of-a-proper-http-
287288

288289
**hsts-preload:** Enables or disables the preload attribute in the HSTS feature (if is enabled)
289290

291+
**ignore-invalid-headers:** set if header fields with invalid names should be ignored. This is 'true' by default.
292+
290293
**keep-alive:** Sets the time during which a keep-alive client connection will stay open on the server side.
291294
The zero value disables keep-alive client connections.
292295
http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
@@ -415,13 +418,15 @@ The following table shows the options, the default value and a description.
415418
|custom-http-errors|" "|
416419
|enable-dynamic-tls-records|"true"|
417420
|enable-sticky-sessions|"false"|
421+
|enable-underscores-in-headers|"false"|
418422
|enable-vts-status|"false"|
419423
|error-log-level|notice|
420424
|gzip-types|see use-gzip description above|
421425
|hsts|"true"|
422426
|hsts-include-subdomains|"true"|
423427
|hsts-max-age|"15724800"|
424428
|hsts-preload|"false"|
429+
|ignore-invalid-headers|"true"|
425430
|keep-alive|"75"|
426431
|map-hash-bucket-size|"64"|
427432
|max-worker-connections|"16384"|

controllers/nginx/pkg/config/config.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ type Configuration struct {
101101
// DisableIpv6 disable listening on ipv6 address
102102
DisableIpv6 bool `json:"disable-ipv6,omitempty"`
103103

104+
// EnableUnderscoresInHeaders enables underscores in header names
105+
// http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers
106+
// By default this is disabled
107+
EnableUnderscoresInHeaders bool `json:"enable-underscores-in-headers"`
108+
109+
// IgnoreInvalidHeaders set if header fields with invalid names should be ignored
110+
// http://nginx.org/en/docs/http/ngx_http_core_module.html#ignore_invalid_headers
111+
// By default this is enabled
112+
IgnoreInvalidHeaders bool `json:"ignore-invalid-headers"`
113+
104114
// EnableStickySessions enabled sticky sessions using cookies
105115
// https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng
106116
// By default this is disabled
@@ -266,15 +276,17 @@ type Configuration struct {
266276
// NewDefault returns the default nginx configuration
267277
func NewDefault() Configuration {
268278
cfg := Configuration{
269-
ClientHeaderBufferSize: "1k",
270-
EnableDynamicTLSRecords: true,
271-
ErrorLogLevel: errorLevel,
272-
HTTP2MaxFieldSize: "4k",
273-
HTTP2MaxHeaderSize: "16k",
274-
HSTS: true,
279+
ClientHeaderBufferSize: "1k",
280+
EnableDynamicTLSRecords: true,
281+
EnableUnderscoresInHeaders: false,
282+
ErrorLogLevel: errorLevel,
283+
HTTP2MaxFieldSize: "4k",
284+
HTTP2MaxHeaderSize: "16k",
285+
HSTS: true,
275286
HSTSIncludeSubdomains: true,
276287
HSTSMaxAge: hstsMaxAge,
277288
HSTSPreload: false,
289+
IgnoreInvalidHeaders: true,
278290
GzipTypes: gzipTypes,
279291
KeepAlive: 75,
280292
LargeClientHeaderBuffers: "4 8k",

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ http {
6969
server_names_hash_bucket_size {{ $cfg.ServerNameHashBucketSize }};
7070
map_hash_bucket_size {{ $cfg.MapHashBucketSize }};
7171

72+
underscores_in_headers {{ if $cfg.IgnoreInvalidHeaders }}on{{ else }}off{{ end }};
73+
ignore_invalid_headers {{ if $cfg.EnableUnderscoresInHeaders }}on{{ else }}off{{ end }};
74+
7275
include /etc/nginx/mime.types;
7376
default_type text/html;
7477
{{ if $cfg.UseGzip }}

0 commit comments

Comments
 (0)