fix: Helm YAML Injection - #1068
Open
dennisvankekem wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens input validation for Kubernetes NetworkPolicy selector labels to mitigate Helm/YAML injection risks by constraining label name/value fields to Kubernetes-compatible regex patterns and extending test coverage around those constraints.
Changes:
- Add
kubernetesLabelNameandkubernetesLabelValueregex definitions (max 63 chars) to the shared OpenAPI definitions. - Update the netpol OpenAPI schema to use these new definitions for
toLabelName/toLabelValueandfromLabelName/fromLabelValue. - Extend unit and API authz tests to cover valid/invalid Kubernetes label names/values and guard against regex ReDoS.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/openapi/definitions.yaml | Introduces reusable regex definitions for Kubernetes label name/value. |
| src/openapi/netpol.yaml | Applies the new label name/value definitions to netpol selector fields via $ref. |
| src/patterns.test.ts | Adds ReDoS cases and validity tests for the new label patterns. |
| src/api-v2.authz.test.ts | Adds API-level validation tests ensuring invalid label values are rejected. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+846
to
+853
| kubernetesLabelName: | ||
| type: string | ||
| maxLength: 63 | ||
| pattern: '^[A-Za-z0-9](?:[-._A-Za-z0-9]{0,61}[A-Za-z0-9])?$' | ||
| kubernetesLabelValue: | ||
| type: string | ||
| maxLength: 63 | ||
| pattern: '^$|^[A-Za-z0-9](?:[-._A-Za-z0-9]{0,61}[A-Za-z0-9])?$' |
Comment on lines
+257
to
+271
| expectInvalid('kubernetesLabelValue', [ | ||
| '-app', | ||
| 'app-', | ||
| '.app', | ||
| 'app.', | ||
| '_app', | ||
| 'app_', | ||
| 'app value', | ||
| 'foo\nbar', | ||
| 'foo\r\nbar', | ||
| '{{ malicious }}', | ||
| 'foo: bar', | ||
| '---', | ||
| 'a'.repeat(64), | ||
| ]) |
Comment on lines
+1193
to
+1194
| it.each(['foo\nbar', 'foo\r\nbar', '{{ malicious }}', 'foo: bar', 'foo bar', '---'])( | ||
| 'rejects invalid label value %p', |
Comment on lines
+281
to
+296
| expectInvalid('kubernetesLabelName', [ | ||
| '', | ||
| '-app', | ||
| 'app-', | ||
| '.app', | ||
| 'app.', | ||
| '_app', | ||
| 'app_', | ||
| 'app name', | ||
| 'foo\nbar', | ||
| 'foo\r\nbar', | ||
| '{{ malicious }}', | ||
| 'foo: bar', | ||
| '---', | ||
| 'a'.repeat(64), | ||
| ]) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.