Skip to content

Commit 5e85747

Browse files
authored
remove tests and regex path checks (#9626)
Signed-off-by: James Strong <[email protected]>
1 parent bbc8bd4 commit 5e85747

File tree

6 files changed

+0
-252
lines changed

6 files changed

+0
-252
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ require (
7777
github.com/inconshreveable/mousetrap v1.0.1 // indirect
7878
github.com/josharian/intern v1.0.0 // indirect
7979
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
80-
github.com/magefile/mage v1.14.0 // indirect
8180
github.com/mailru/easyjson v0.7.6 // indirect
8281
github.com/mattn/go-colorable v0.1.13 // indirect
8382
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
235235
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
236236
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
237237
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
238-
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
239-
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
240238
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
241239
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
242240
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=

internal/ingress/controller/store/store.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import (
5959
"k8s.io/ingress-nginx/internal/ingress/resolver"
6060
"k8s.io/ingress-nginx/internal/k8s"
6161
"k8s.io/ingress-nginx/pkg/apis/ingress"
62-
ingressutils "k8s.io/ingress-nginx/pkg/util/ingress"
6362
)
6463

6564
// IngressFilterFunc decides if an Ingress should be omitted or not
@@ -865,10 +864,6 @@ func (s *k8sStore) syncIngress(ing *networkingv1.Ingress) {
865864
if path.Path == "" {
866865
copyIng.Spec.Rules[ri].HTTP.Paths[pi].Path = "/"
867866
}
868-
if !ingressutils.IsSafePath(copyIng, path.Path) {
869-
klog.Warningf("ingress %s contains invalid path %s", key, path.Path)
870-
return
871-
}
872867
}
873868
}
874869

pkg/util/ingress/ingress.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,15 @@ package ingress
1818

1919
import (
2020
"fmt"
21-
"regexp"
2221
"strings"
2322

24-
networkingv1 "k8s.io/api/networking/v1"
2523
"k8s.io/apimachinery/pkg/util/sets"
26-
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
2724
"k8s.io/ingress-nginx/internal/k8s"
2825
"k8s.io/ingress-nginx/internal/net/ssl"
2926
"k8s.io/ingress-nginx/pkg/apis/ingress"
3027
"k8s.io/klog/v2"
3128
)
3229

33-
const (
34-
alphaNumericChars = `\-\.\_\~a-zA-Z0-9/`
35-
regexEnabledChars = `\^\$\[\]\(\)\{\}\*\+`
36-
)
37-
38-
var (
39-
// pathAlphaNumeric is a regex validation of something like "^/[a-zA-Z]+$" on path
40-
pathAlphaNumeric = regexp.MustCompile("^/[" + alphaNumericChars + "]*$").MatchString
41-
// pathRegexEnabled is a regex validation of paths that may contain regex.
42-
pathRegexEnabled = regexp.MustCompile("^/[" + alphaNumericChars + regexEnabledChars + "]*$").MatchString
43-
)
44-
4530
func GetRemovedHosts(rucfg, newcfg *ingress.Configuration) []string {
4631
oldSet := sets.NewString()
4732
newSet := sets.NewString()
@@ -246,13 +231,3 @@ func BuildRedirects(servers []*ingress.Server) []*redirect {
246231

247232
return redirectServers
248233
}
249-
250-
// IsSafePath verifies if the path used in ingress object contains only valid characters.
251-
// It will behave differently if regex is enabled or not
252-
func IsSafePath(copyIng *networkingv1.Ingress, path string) bool {
253-
isRegex, _ := parser.GetBoolAnnotation("use-regex", copyIng)
254-
if isRegex {
255-
return pathRegexEnabled(path)
256-
}
257-
return pathAlphaNumeric(path)
258-
}

pkg/util/ingress/ingress_test.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ limitations under the License.
1717
package ingress
1818

1919
import (
20-
"fmt"
2120
"testing"
2221

23-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
25-
networkingv1 "k8s.io/api/networking/v1"
26-
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
2722
"k8s.io/ingress-nginx/pkg/apis/ingress"
2823
)
2924

@@ -135,83 +130,3 @@ func TestIsDynamicConfigurationEnough(t *testing.T) {
135130
t.Errorf("Expected new config to not change")
136131
}
137132
}
138-
139-
func generateDumbIngressforPathTest(regexEnabled bool) *networkingv1.Ingress {
140-
var annotations = make(map[string]string)
141-
regexAnnotation := fmt.Sprintf("%s/use-regex", parser.AnnotationsPrefix)
142-
if regexEnabled {
143-
annotations[regexAnnotation] = "true"
144-
}
145-
return &networkingv1.Ingress{
146-
ObjectMeta: metav1.ObjectMeta{
147-
Name: "dumb",
148-
Namespace: "default",
149-
Annotations: annotations,
150-
},
151-
}
152-
}
153-
154-
func TestIsSafePath(t *testing.T) {
155-
tests := []struct {
156-
name string
157-
copyIng *networkingv1.Ingress
158-
path string
159-
want bool
160-
}{
161-
{
162-
name: "should accept valid path with regex disabled",
163-
want: true,
164-
copyIng: generateDumbIngressforPathTest(false),
165-
path: "/xpto/~user/t-e_st.exe",
166-
},
167-
{
168-
name: "should accept valid path / with regex disabled",
169-
want: true,
170-
copyIng: generateDumbIngressforPathTest(false),
171-
path: "/",
172-
},
173-
{
174-
name: "should reject invalid path with invalid chars",
175-
want: false,
176-
copyIng: generateDumbIngressforPathTest(false),
177-
path: "/foo/bar/;xpto",
178-
},
179-
{
180-
name: "should reject regex path when regex is disabled",
181-
want: false,
182-
copyIng: generateDumbIngressforPathTest(false),
183-
path: "/foo/bar/(.+)",
184-
},
185-
{
186-
name: "should accept valid path / with regex enabled",
187-
want: true,
188-
copyIng: generateDumbIngressforPathTest(true),
189-
path: "/",
190-
},
191-
{
192-
name: "should accept regex path when regex is enabled",
193-
want: true,
194-
copyIng: generateDumbIngressforPathTest(true),
195-
path: "/foo/bar/(.+)",
196-
},
197-
{
198-
name: "should reject regex path when regex is enabled but the path is invalid",
199-
want: false,
200-
copyIng: generateDumbIngressforPathTest(true),
201-
path: "/foo/bar/;xpto",
202-
},
203-
{
204-
name: "should reject regex path when regex is enabled but the path is invalid",
205-
want: false,
206-
copyIng: generateDumbIngressforPathTest(true),
207-
path: ";xpto",
208-
},
209-
}
210-
for _, tt := range tests {
211-
t.Run(tt.name, func(t *testing.T) {
212-
if got := IsSafePath(tt.copyIng, tt.path); got != tt.want {
213-
t.Errorf("IsSafePath() = %v, want %v", got, tt.want)
214-
}
215-
})
216-
}
217-
}

test/e2e/security/invalid_paths.go

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)