forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Route Validation (#7595) * inital commit * ReWrites added * fix issue with Focus * adding changelog * update * code gen update * allow "/" * update validation of path * updated route reporting with route validation * clean up code * moving some code around, and cleanning up some things * clean up * added a test * set the normalized path to true * Update changelog/v1.14.0-beta4/validate-routes.yaml Co-authored-by: Nathan Fudenberg <[email protected]> * Update projects/gloo/pkg/translator/route_config.go Co-authored-by: Nathan Fudenberg <[email protected]> * correct nits * Update projects/gloo/pkg/translator/route_config.go Co-authored-by: Nathan Fudenberg <[email protected]> * comments * global regex * comments on hcm * add full list of tests to validate route paths * update changelog Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Nathan Fudenberg <[email protected]> * fix * update generated code Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Nathan Fudenberg <[email protected]>
- Loading branch information
1 parent
23f2935
commit b2bd007
Showing
9 changed files
with
287 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
changelog: | ||
- type: FIX | ||
description: | | ||
Add route validation to reject and sanitize invalid paths. | ||
Set the normalized_path attribute for the [Envoy HTTP Connection Manager](https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto.html?highlight=hcm) to true as the default value. | ||
issueLink: https://github.com/solo-io/solo-projects/issues/4336 | ||
resolvesIssue: false |
2 changes: 1 addition & 1 deletion
2
...ce/api/github.com/solo-io/gloo/projects/gloo/api/v1/options/hcm/hcm.proto.sk.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package translator_test | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/translator" | ||
) | ||
|
||
var _ = Describe("Route Configs", func() { | ||
|
||
DescribeTable("validate route path", func(path string, expectedValue bool) { | ||
if expectedValue { | ||
Expect(translator.ValidateRoutePath(path)).ToNot(HaveOccurred()) | ||
} else { | ||
Expect(translator.ValidateRoutePath(path)).To(HaveOccurred()) | ||
} | ||
}, | ||
Entry("Hex", "%af", true), | ||
Entry("Hex Camel", "%Af", true), | ||
Entry("Hex num", "%00", true), | ||
Entry("Hex double", "%11", true), | ||
Entry("Hex with valid", "%af801&*", true), | ||
Entry("valid with hex", "801&*%af", true), | ||
Entry("valid with hex and valid", "801&*%af719$@!", true), | ||
Entry("Hex single", "%0", false), | ||
Entry("unicode chars", "ĩ", false), | ||
Entry("unicode chars", "¥¨˚∫", false), | ||
Entry("//", "hello/something//", false), | ||
Entry("/./", "hello/something/./", false), | ||
Entry("/../", "hello/something/../", false), | ||
Entry("hex slash upper", "hello/something%2F", false), | ||
Entry("hex slash lower", "hello/something%2f", false), | ||
Entry("hash", "hello/something#", false), | ||
Entry("/..", "hello/../something", false), | ||
Entry("/.", "hello/./something", false), | ||
) | ||
|
||
It("Should validate all seperate characters", func() { | ||
// must allow all "pchar" characters = unreserved / pct-encoded / sub-delims / ":" / "@" | ||
// https://www.rfc-editor.org/rfc/rfc3986 | ||
// unreserved | ||
// alpha Upper and Lower | ||
for i := 'a'; i <= 'z'; i++ { | ||
Expect(translator.ValidateRoutePath(string(i))).ToNot(HaveOccurred()) | ||
Expect(translator.ValidateRoutePath(strings.ToUpper(string(i)))).ToNot(HaveOccurred()) | ||
} | ||
// digit | ||
for i := 0; i < 10; i++ { | ||
Expect(translator.ValidateRoutePath(strconv.Itoa(i))).ToNot(HaveOccurred()) | ||
} | ||
unreservedChars := "-._~" | ||
for _, c := range unreservedChars { | ||
Expect(translator.ValidateRoutePath(string(c))).ToNot(HaveOccurred()) | ||
} | ||
// sub-delims | ||
subDelims := "!$&'()*+,;=" | ||
Expect(len(subDelims)).To(Equal(11)) | ||
for _, c := range subDelims { | ||
Expect(translator.ValidateRoutePath(string(c))).ToNot(HaveOccurred()) | ||
} | ||
// pchar | ||
pchar := ":@" | ||
for _, c := range pchar { | ||
Expect(translator.ValidateRoutePath(string(c))).ToNot(HaveOccurred()) | ||
} | ||
// invalid characters | ||
invalid := "<>?\\|[]{}\"^%#" | ||
for _, c := range invalid { | ||
Expect(translator.ValidateRoutePath(string(c))).To(HaveOccurred()) | ||
} | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters