Skip to content

Commit

Permalink
Correct header name validation (#1239)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjee19 authored Nov 10, 2023
1 parent 32e2d70 commit 6628e38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (HTTPNJSMatchValidator) ValidatePathInMatch(path string) error {
}

func (HTTPNJSMatchValidator) ValidateHeaderNameInMatch(name string) error {
if err := k8svalidation.IsHTTPHeaderName(name); err != nil {
return errors.New(err[0])
}

return validateNJSHeaderPart(name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ func TestValidateHeaderNameInMatch(t *testing.T) {
t,
validator.ValidateHeaderNameInMatch,
"header",
"version",
"version-2",
)
testInvalidValuesForSimpleValidator(
t,
validator.ValidateHeaderNameInMatch,
":",
"",
"version%!",
"version_2",
"hello$world",
" ",
)
}

Expand All @@ -50,12 +56,16 @@ func TestValidateHeaderValueInMatch(t *testing.T) {
t,
validator.ValidateHeaderValueInMatch,
"value",
"version%!",
"version-2",
)
testInvalidValuesForSimpleValidator(
t,
validator.ValidateHeaderValueInMatch,
":",
"",
"hello$world",
" ",
)
}

Expand Down

0 comments on commit 6628e38

Please sign in to comment.