Skip to content

Fix translation paths in proxy - #371

Closed
drk1wi with Copilot wants to merge 1 commit into
masterfrom
copilot/follow-whole-proxy-translation-paths
Closed

Fix translation paths in proxy#371
drk1wi with Copilot wants to merge 1 commit into
masterfrom
copilot/follow-whole-proxy-translation-paths

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

The proxy translation logic was previously mishandling multi-origin setups by using Header.Get() (which drops all but the first header value) and by unconditionally overriding the backend's CORS headers with the client's origin.

Changes

  • Header Slice Iteration: Refactored the patching logic for Origin, Referer, Cookie, WWW-Authenticate, and Access-Control-Allow-Origin to iterate over all header values (Header["Name"]) rather than just the first one.
  • CORS Translation: Modified Access-Control-Allow-Origin patching to translate backend-provided origins (using RealURLtoPhish) instead of blindly forcing it to the client's request origin. This correctly preserves dynamic multi-origin configurations from the backend.
  • CORS Fallback: Maintained the fallback behavior to inject the requested Origin and Access-Control-Allow-Credentials: true only if the backend server does not provide an Access-Control-Allow-Origin header.
// Translating backend-provided origins properly supports multi-origin setups
if len(httpResponse.Header["Access-Control-Allow-Origin"]) > 0 {
    setCredentials := false
    for i, oldOrigin := range httpResponse.Header["Access-Control-Allow-Origin"] {
        if oldOrigin == "*" || oldOrigin == "null" {
            log.Debugf("Not rewriting Access-Control-Allow-Origin: [%s]", oldOrigin)
        } else {
            newOrigin := runtime.RegexpUrl.ReplaceAllStringFunc(oldOrigin, runtime.RealURLtoPhish)
            httpResponse.Header["Access-Control-Allow-Origin"][i] = newOrigin
            setCredentials = true
        }
    }
    if setCredentials {
        httpResponse.Header.Set("Access-Control-Allow-Credentials", "true")
    }
} else if p.Origin != "" {
    // Fallback if no backend CORS header is provided
    httpResponse.Header.Set("Access-Control-Allow-Origin", p.Origin)
    httpResponse.Header.Set("Access-Control-Allow-Credentials", "true")
}

Co-authored-by: drk1wi <2052966+drk1wi@users.noreply.github.com>
Copilot AI changed the title Fix multi-origin proxy translation paths Fix multi-origin translation paths in proxy Aug 14, 2026
Copilot AI requested a review from drk1wi August 14, 2026 14:09
@drk1wi drk1wi closed this Aug 14, 2026
@drk1wi
drk1wi deleted the copilot/follow-whole-proxy-translation-paths branch August 14, 2026 14:29
@drk1wi drk1wi changed the title Fix multi-origin translation paths in proxy Fix translation paths in proxy Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants