[Repo Assist] refactor(auth): move IsMalformedHeader from server to auth package#4144
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
The isMalformedAuthHeader function implements RFC 7230 header validation logic that belongs in the internal/auth package alongside other header parsing utilities (ParseAuthHeader, ExtractSessionID, etc.). Changes: - Add exported auth.IsMalformedHeader to internal/auth/header.go - Remove private isMalformedAuthHeader from internal/server/auth.go - Update server/auth.go to call auth.IsMalformedHeader - Update server/auth_test.go to call auth.IsMalformedHeader - Add TestIsMalformedHeader with 12 cases to internal/auth/header_test.go This makes all header validation logic discoverable in one place and ensures future additions follow the same pattern. Closes #4138 (partial: addresses Issue 3 from the analysis) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Moves the RFC 7230 header-character validation logic out of
internal/server/auth.gointointernal/auth/header.go, where all other header-parsing utilities already live.This addresses Issue 3 from the automated Semantic Function Clustering Analysis (#4138), which identified that
isMalformedAuthHeaderis conceptually misplaced — it validates raw header bytes per RFC 7230 before any auth parsing, and belongs alongsideParseAuthHeader,ExtractSessionID,ValidateAPIKey, etc.Changes
internal/auth/header.go— Add exportedIsMalformedHeader(header string) boolinternal/server/auth.go— Remove privateisMalformedAuthHeader; importinternal/auth; callauth.IsMalformedHeaderinternal/auth/header_test.go— AddTestIsMalformedHeaderwith 12 test cases (empty string, normal key, horizontal tab, null byte, control chars 0x01/0x0A/0x0D/0x1F, DEL 0x7F, etc.)internal/server/auth_test.go— UpdateTestIsMalformedAuthHeaderto callauth.IsMalformedHeader(no logic change; existing 10 cases preserved)Rationale
Before this change,
server/auth.gocontained a comment pointing maintainers atinternal/authfor header logic — yet itself held a piece of header validation. After this change, all header validation lives in one package and can be used by any future callers without importing the server package.Test Status
The environment has Go 1.24.13; the module requires Go 1.25.0 (network-restricted — toolchain download blocked). Build and test could not be run locally. CI will provide authoritative results.
The logic in
IsMalformedHeaderis identical to the previousisMalformedAuthHeader— only renamed and relocated. The existing 10 unit tests inserver/auth_test.gocontinue to cover the same code paths via the newauth.IsMalformedHeadercall, and 12 new cases are added directly toauth/header_test.go.Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.