Skip to content

Pattern validation for HTTP header values according to RFC 7230 #3774

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

snorwin
Copy link
Contributor

@snorwin snorwin commented Apr 28, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:
This PR adds an experimental pattern validation to ensure that HTTP header values consist only of printable US-ASCII characters, optionally separated by spaces or tabs, as required by RFC 7230.

Which issue(s) this PR fixes:

Fixes #3669

Does this PR introduce a user-facing change?:

Pattern validation for HTTP header values according to RFC 7230

Signed-off-by: Norwin Schnyder <[email protected]>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Apr 28, 2025
@k8s-ci-robot k8s-ci-robot requested a review from mlavacca April 28, 2025 11:24
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 28, 2025
@k8s-ci-robot k8s-ci-robot requested a review from youngnick April 28, 2025 11:24
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 28, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @snorwin. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 28, 2025
@snorwin snorwin changed the title CEL validation for HTTP header values according to RFC 7230 Pattern validation for HTTP header values according to RFC 7230 Apr 28, 2025
@snorwin snorwin force-pushed the httpheadervalue-cel branch from 3ff6e20 to 722ac23 Compare April 28, 2025 11:53
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=4096
// <gateway:experimental:validation:XValidation:message="must only contain printable ASCII characters, optionally separated by single tabs or spaces",rule="self.matches('^[!-~]+([\\t ]?[!-~]+)*$')">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While a CEL would offer a cleaner approach with meaningful error messages, the complexity appears to be too high.

@snorwin snorwin force-pushed the httpheadervalue-cel branch from 722ac23 to 0a5580a Compare May 9, 2025 07:44
@youngnick
Copy link
Contributor

/ok-to-test
/approve

I think that @robscott should check this out as well though.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 14, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: snorwin, youngnick

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 14, 2025
@k8s-ci-robot
Copy link
Contributor

@snorwin: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-gateway-api-verify 0a5580a link true /test pull-gateway-api-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @snorwin! I'm very hesitant to ever tighten validation on a GA API, but as long as we can have complete confidence that all configuration that would fail this validation would have been useless/invalid before this validation, this does seem like a net improvement.

/cc @htuch @mkosieradzki

//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=4096
// <gateway:experimental:validation:Pattern=`^[!-~]+([\t ]?[!-~]+)*$`>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note - this is a header value matcher that supports two types of matches - exact and regex. I believe all forms of regex matcher used here would also be contained within US-ASCII characters, but would appreciate another confirmation of that.

@k8s-ci-robot
Copy link
Contributor

@robscott: GitHub didn't allow me to request PR reviews from the following users: htuch, mkosieradzki.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Thanks @snorwin! I'm very hesitant to ever tighten validation on a GA API, but as long as we can have complete confidence that all configuration that would fail this validation would have been useless/invalid before this validation, this does seem like a net improvement.

/cc @htuch @mkosieradzki

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing validation of value field in HTTPHeader
4 participants