[Repo Assist] refactor(server): extract session ID header extraction into helper#7151
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
Deduplicate the identical 3-line session ID extraction block that appeared in both extractAndValidateSession (session.go) and WithSDKLogging (middleware.go). Add extractSessionIDFromRequest(r *http.Request) string as a package-private helper in session.go that wraps the call to auth.ExtractSessionIDFromHeaders. Both callers are updated to use the new helper. This closes issue #7137 (security-sensitive duplication). Keeping the extraction logic in one place means any future header-name change (e.g., adding X-Session-ID) only needs to be made once. Closes #7137 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
Addresses the security-sensitive duplication identified in issue #7137. An identical 3-line block that extracts the session ID from
X-Agent-IDandAuthorizationheaders was duplicated in two places withininternal/server:session.go:124–126— insideextractAndValidateSession()middleware.go:194–196— insideWithSDKLogging()If the header names change (e.g., a new
X-Session-IDheader is added) or the extraction logic shifts, a missed update could cause session tracking divergence — the middleware's logging could show a different session ID than the one actually used for authentication.Changes
internal/server/session.go— add package-private helper:The
extractAndValidateSessionfunction is updated to call this helper instead of repeating the 3-line extraction block.internal/server/middleware.go—WithSDKLoggingupdated to callextractSessionIDFromRequest(r)instead of the inline 3-line block.No imports were added or removed (both packages already imported
auth).Test Status
Build and tests could not be run —
proxy.golang.orgis blocked in this environment (pre-existing infrastructure limitation). The changes are syntactically verified by inspection:session.goauthimport remains in both files (still used elsewhere)Closes #7137
Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
proxy.golang.orgreleaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run