Skip to content

[codex] fix: guard DPoP fallback URL construction#3503

Open
StiensWout wants to merge 6 commits into
pingdotgg:mainfrom
StiensWout:staging/fix-dpop-fallback-url-guard
Open

[codex] fix: guard DPoP fallback URL construction#3503
StiensWout wants to merge 6 commits into
pingdotgg:mainfrom
StiensWout:staging/fix-dpop-fallback-url-guard

Conversation

@StiensWout

@StiensWout StiensWout commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Guard DPoP fallback request URL construction so malformed Host or request URL values return null instead of throwing.
  • Convert an unnormalizable DPoP request URL into an invalid-credentials auth failure before proof verification.

Root cause

requestAbsoluteUrl caught invalid absolute originalUrl parsing, then built a fallback URL from originalUrl and Host without guarding that second new URL(...) call.

Impact

Malformed Host values during DPoP auth now fail as ServerAuthInvalidCredentialError with Invalid DPoP request URL. instead of surfacing as a defect. Valid absolute URLs and existing relative URL fallback behavior are preserved.

Validation

  • PATH="$HOME/.vite-plus/bin:$PATH" vp test apps/server/src/auth/dpop.test.ts
  • PATH="$HOME/.vite-plus/bin:$PATH" vp check
  • PATH="$HOME/.vite-plus/bin:$PATH" vp run typecheck

Note

Medium Risk
Touches authentication and DPoP URL binding; malformed or previously edge-case URLs may now be rejected rather than verified or throwing at runtime.

Overview
DPoP proof verification no longer builds request URLs locally. verifyRequestDpopProof now resolves the request URL with HttpServerRequest.toURL and, when that returns None, fails with ServerAuthInvalidCredentialError (Invalid DPoP request URL.) before calling verifyDpopProof.

This removes the previous requestAbsoluteUrl / firstHeaderValue fallback path that could still throw on a second new URL(...) when Host or related inputs were malformed. Valid absolute URLs and normal relative-URL resolution behavior are intended to stay the same; unresolvable URLs become explicit credential failures instead of defects or ambiguous verification input.

Reviewed by Cursor Bugbot for commit f1e04ed. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Guard DPoP proof verification against unresolvable request URLs

Replaces the local requestAbsoluteUrl helper in dpop.ts with HttpServerRequest.toURL() to derive the request URL for DPoP proof verification. When toURL returns None, verifyRequestDpopProof now rejects the request early with a ServerAuthInvalidCredentialError (diagnostic: "Invalid DPoP request URL.") instead of proceeding with a potentially malformed URL.

Macroscope summarized f1e04ed.

StiensWout and others added 2 commits June 22, 2026 10:40
Co-authored-by: Codex <codex@openai.com>
…-guard

[codex] fix: guard DPoP fallback URL construction
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 981087cf-a411-4d91-bf14-b6bebd7c63df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jun 22, 2026
@macroscopeapp

macroscopeapp Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

Changes to auth code require human review. Additionally, this modifies error handling behavior - requests that previously used fallback URL construction will now return authentication errors when URL parsing fails.

You can customize Macroscope's approvability policy. Learn more.

Comment thread apps/server/src/auth/dpop.ts Outdated
Comment on lines 21 to 34
export function requestAbsoluteUrl(request: HttpServerRequest.HttpServerRequest): string | null {
try {
return new URL(request.originalUrl).href;
} catch {
const host = firstHeaderValue(request.headers.host) ?? "127.0.0.1";
const forwardedProto = firstHeaderValue(request.headers["x-forwarded-proto"]);
const proto = forwardedProto === "https" || forwardedProto === "http" ? forwardedProto : "http";
return new URL(request.originalUrl, `${proto}://${host}`).href;
try {
return new URL(request.originalUrl, `${proto}://${host}`).href;
} catch {
return null;
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why we don't just use HttpServerRequest.toURL(request). Returns an Option.Option<URL>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use HttpServerRequest.toURL(request) and kept the invalid-url guard.

@juliusmarminge juliusmarminge enabled auto-merge (squash) June 22, 2026 17:13
Co-authored-by: Codex <codex@openai.com>
auto-merge was automatically disabled June 22, 2026 17:34

Head branch was pushed to by a user without write access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants