-
Notifications
You must be signed in to change notification settings - Fork 12
HYPERFLEET-649 - fix: Reject cluster creation with missing spec field #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,3 +113,23 @@ func validateKind(i interface{}, fieldName string, field string, expectedKind st | |
| return nil | ||
| } | ||
| } | ||
|
|
||
| // validateSpec validates that the spec field is not nil | ||
| func validateSpec(i interface{}, fieldName string, field string) validate { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validateSpec function doesn't follow the same defensive pattern used by all other func validateSpec(i interface{}, fieldName string, field string) validate {
return func() *errors.ServiceError {
value := reflect.ValueOf(i).Elem().FieldByName(fieldName)
if value.Kind() == reflect.Ptr {
if value.IsNil() {
return errors.Validation("%s is required", field)
}
value = value.Elem()
}
if !value.IsValid() || value.IsNil() {
return errors.Validation("%s is required", field)
}
return nil
}
}This makes the function safe for reuse if the Spec type ever changes (e.g., to a pointer to a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| return func() *errors.ServiceError { | ||
| value := reflect.ValueOf(i).Elem().FieldByName(fieldName) | ||
|
|
||
| if value.Kind() == reflect.Ptr { | ||
| if value.IsNil() { | ||
| return errors.Validation("%s is required", field) | ||
| } | ||
| value = value.Elem() | ||
| } | ||
|
|
||
| if !value.IsValid() || value.IsNil() { | ||
| return errors.Validation("%s is required", field) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validateSpec check was added to the cluster creation handler, but the nodepool creation
handler in cluster_nodepools.go has the same gap. The NodePoolCreateRequest schema also
defines spec as a required field, and the SchemaValidationMiddleware skips validation when the
spec key is entirely absent from the JSON body (it only catches spec: null). This means a
nodepool can still be created without a spec field.
Consider adding validateSpec(&req, "Spec", "spec") to the validators list in
clusterNodePoolsHandler.Create:
This may be intentionally out of scope for this ticket, but worth noting since it's the same
vulnerability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! I will include it in this PR since its same bug with same solution both violating OpenAPI specification.