OCPBUGS-88729: Fix HSTS annotation regex to reject newlines and accept trailing semicolons#803
Conversation
…t trailing semicolons The HSTS regex uses \s* for whitespace matching, which also matches newlines. An annotation like "max-age=31536000\n;\npreload" passes the regex but injects newlines into the HAProxy config, breaking reload and taking down all routes cluster-wide. Fix by replacing \s* with [ \t]* so only spaces and tabs are allowed. While here, also allow a trailing semicolon in the annotation value. This was silently rejected before, so the HSTS header would never get set even though the route was admitted without errors. Assisted with Claude
|
@Thealisyed: This pull request references Jira Issue OCPBUGS-88729, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughThe ChangesHSTS Header Pattern Fix and Tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (13 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@Thealisyed: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
Summary
\s*with[ \t]*in the HSTS regex pattern to reject newline characters (\n,\r,\f) that break HAProxy config on reload and can cause cluster-wide router unavailabilityStrict-Transport-Securityheader to not be setThe Issue
The HSTS regex in
haproxy-config.template:31used\s*to match whitespace between directives. In Go,\smatches[\t\n\f\r ]— including newlines. An annotation likemax-age=31536000\n;\npreloadwould pass the regex, render literal newlines into the HAProxy config, and cause HAProxy to reject the entire config on reload — taking down all routes cluster-wide.Solution
Two changes to the same regex:
\s*→[ \t]*— restricts whitespace matching to horizontal whitespace only (spaces and tabs)(?:[ \t]*;)?— allows an optional trailing semicolon, fixing a silent failure that has existed since 2018 (openshift/origin#19860)Summary by CodeRabbit
Bug Fixes
Tests