Skip to content

Commit 6628e38

Browse files
authored
Correct header name validation (#1239)
Correct header name validation. Problem: Header name validation was not being implemented by NGF thus any problems would be caught by nginx and would not be as visible. Solution: NGF now validates header names and will show an error in the HTTPRoute status.
1 parent 32e2d70 commit 6628e38

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/mode/static/nginx/config/validation/http_njs_match.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (HTTPNJSMatchValidator) ValidatePathInMatch(path string) error {
4646
}
4747

4848
func (HTTPNJSMatchValidator) ValidateHeaderNameInMatch(name string) error {
49+
if err := k8svalidation.IsHTTPHeaderName(name); err != nil {
50+
return errors.New(err[0])
51+
}
52+
4953
return validateNJSHeaderPart(name)
5054
}
5155

internal/mode/static/nginx/config/validation/http_njs_match_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ func TestValidateHeaderNameInMatch(t *testing.T) {
3434
t,
3535
validator.ValidateHeaderNameInMatch,
3636
"header",
37+
"version",
38+
"version-2",
3739
)
3840
testInvalidValuesForSimpleValidator(
3941
t,
4042
validator.ValidateHeaderNameInMatch,
4143
":",
4244
"",
45+
"version%!",
46+
"version_2",
47+
"hello$world",
48+
" ",
4349
)
4450
}
4551

@@ -50,12 +56,16 @@ func TestValidateHeaderValueInMatch(t *testing.T) {
5056
t,
5157
validator.ValidateHeaderValueInMatch,
5258
"value",
59+
"version%!",
60+
"version-2",
5361
)
5462
testInvalidValuesForSimpleValidator(
5563
t,
5664
validator.ValidateHeaderValueInMatch,
5765
":",
5866
"",
67+
"hello$world",
68+
" ",
5969
)
6070
}
6171

0 commit comments

Comments
 (0)