Skip to content

Commit 698c3c0

Browse files
authored
Annotations: Deny newlines. (#12640)
1 parent 63d4d64 commit 698c3c0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

internal/ingress/annotations/parser/validators.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var (
7979
// URLWithNginxVariableRegex defines a url that can contain nginx variables.
8080
// It is a risky operation
8181
URLWithNginxVariableRegex = regexp.MustCompile("^[" + extendedAlphaNumeric + urlEnabledChars + "$]*$")
82+
// MaliciousRegex defines chars that are known to inject RCE
83+
MaliciousRegex = regexp.MustCompile(`\r|\n`)
8284
)
8385

8486
// ValidateArrayOfServerName validates if all fields on a Server name annotation are
@@ -113,6 +115,10 @@ func ValidateRegex(regex *regexp.Regexp, removeSpace bool) AnnotationValidator {
113115
if !regex.MatchString(s) {
114116
return fmt.Errorf("value %s is invalid", s)
115117
}
118+
if MaliciousRegex.MatchString(s) {
119+
return fmt.Errorf("value %s contains malicious string", s)
120+
}
121+
116122
return nil
117123
}
118124
}

internal/ingress/annotations/parser/validators_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func TestValidateArrayOfServerName(t *testing.T) {
6565
value: "something.com,lolo;xpto.com,nothing.com",
6666
wantErr: true,
6767
},
68+
{
69+
name: "should deny names with malicous chars",
70+
value: "http://something.com/#;\nournewinjection",
71+
wantErr: true,
72+
},
6873
}
6974
for _, tt := range tests {
7075
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)