Skip to content

Commit d83bbb4

Browse files
author
Kate Osborn
committed
Remove unnecessary validation
1 parent 6d3fb91 commit d83bbb4

File tree

2 files changed

+2
-41
lines changed

2 files changed

+2
-41
lines changed

internal/mode/static/policies/clientsettings/validator.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func validateTargetRef(ref v1alpha2.LocalPolicyTargetReference, policyNs string)
107107
return nil
108108
}
109109

110+
// validateSettings performs validation on fields in the spec that are vulnerable to code injection.
111+
// For all other fields, we rely on the CRD validation.
110112
func (v *Validator) validateSettings(spec ngfAPI.ClientSettingsPolicySpec) error {
111113
var allErrs field.ErrorList
112114
fieldPath := field.NewPath("spec")
@@ -146,18 +148,6 @@ func (v *Validator) validateClientBody(body ngfAPI.ClientBody, fieldPath *field.
146148
func (v *Validator) validateClientKeepAlive(keepAlive ngfAPI.ClientKeepAlive, fieldPath *field.Path) field.ErrorList {
147149
var allErrs field.ErrorList
148150

149-
if keepAlive.Requests != nil {
150-
requests := *keepAlive.Requests
151-
if requests < 0 {
152-
path := fieldPath.Child("requests")
153-
154-
allErrs = append(
155-
allErrs,
156-
field.Invalid(path, *keepAlive.Requests, "requests is invalid: must be positive"),
157-
)
158-
}
159-
}
160-
161151
if keepAlive.Time != nil {
162152
if err := v.genericValidator.ValidateNginxDuration(string(*keepAlive.Time)); err != nil {
163153
path := fieldPath.Child("time")
@@ -190,19 +180,6 @@ func (v *Validator) validateClientKeepAlive(keepAlive ngfAPI.ClientKeepAlive, fi
190180
)
191181
}
192182
}
193-
194-
if keepAlive.Timeout.Header != nil && keepAlive.Timeout.Server == nil {
195-
path := fieldPath.Child("timeout")
196-
197-
allErrs = append(
198-
allErrs,
199-
field.Invalid(
200-
path,
201-
nil,
202-
"server timeout must be set if header timeout is set",
203-
),
204-
)
205-
}
206183
}
207184

208185
return allErrs

internal/mode/static/policies/clientsettings/validator_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,6 @@ func TestValidator_Validate(t *testing.T) {
9696
"spec.keepAlive.timeout.header",
9797
},
9898
},
99-
{
100-
name: "invalid keepalive requests",
101-
policy: createModifiedPolicy(func(p *ngfAPI.ClientSettingsPolicy) *ngfAPI.ClientSettingsPolicy {
102-
p.Spec.KeepAlive.Requests = helpers.GetPointer[int32](-1)
103-
return p
104-
}),
105-
expErrSubstrings: []string{"spec.keepAlive.requests"},
106-
},
107-
{
108-
name: "invalid keepalive timeout; header provided without server",
109-
policy: createModifiedPolicy(func(p *ngfAPI.ClientSettingsPolicy) *ngfAPI.ClientSettingsPolicy {
110-
p.Spec.KeepAlive.Timeout.Server = nil
111-
return p
112-
}),
113-
expErrSubstrings: []string{"spec.keepAlive.timeout"},
114-
},
11599
{
116100
name: "valid",
117101
policy: createValidPolicy(),

0 commit comments

Comments
 (0)