Skip to content

[Repo Assist] refactor(server): extract session ID header extraction into helper#7151

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/refactor-session-id-helper-7137-40c771877d950de7
Draft

[Repo Assist] refactor(server): extract session ID header extraction into helper#7151
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/refactor-session-id-helper-7137-40c771877d950de7

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 7, 2026

🤖 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-ID and Authorization headers was duplicated in two places within internal/server:

  • session.go:124–126 — inside extractAndValidateSession()
  • middleware.go:194–196 — inside WithSDKLogging()

If the header names change (e.g., a new X-Session-ID header 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:

// extractSessionIDFromRequest extracts the session ID from the X-Agent-ID and
// Authorization headers of an HTTP request. Returns "" if neither header is present.
func extractSessionIDFromRequest(r *http.Request) string {
    return auth.ExtractSessionIDFromHeaders(
        r.Header.Get("X-Agent-ID"),
        r.Header.Get("Authorization"),
    )
}

The extractAndValidateSession function is updated to call this helper instead of repeating the 3-line extraction block.

internal/server/middleware.goWithSDKLogging updated to call extractSessionIDFromRequest(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.org is blocked in this environment (pre-existing infrastructure limitation). The changes are syntactically verified by inspection:

  • The helper is placed before its first caller in session.go
  • Both call sites are updated identically
  • The auth import 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.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Repo Assist · sonnet46 8M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Session ID Extraction from Request Headers (2 locations, security-sensitive)

0 participants