Skip to content

fix(auth): return_url の schemes / opaque / backslash を拒否#151

Open
anko9801 wants to merge 1 commit into
mainfrom
fix/sanitize-return-url-strict
Open

fix(auth): return_url の schemes / opaque / backslash を拒否#151
anko9801 wants to merge 1 commit into
mainfrom
fix/sanitize-return-url-strict

Conversation

@anko9801
Copy link
Copy Markdown
Collaborator

@anko9801 anko9801 commented May 5, 2026

概要

  • return_url は単一の / で始まる文字列のみ許可し、///\ は拒否する。
  • さらに Scheme / Host / Opaque のいずれかが non-empty な URL も拒否対象とする。これで javascript:alert(1)mailto:... も通らなくなる。
  • 悪意ある入力パターンを網羅した table-driven な unit test を追加する。

背景

従来のフィルタは url.Parse 後に Host が non-empty かどうかしか確認していなかった。古典的な open-redirect ベクタが 2 種類通過していた:

  • javascript:alert(1)url.Parse は Host を空にして Opaque に格納するため、フィルタを通過していた。
  • /\evil.com/path — 一部のブラウザは backslash を / に正規化し、protocol-relative URL として解釈して evil.com にリダイレクトする。url.Parse の挙動とは一致しない。

いずれもログイン成功後に /login?return_url=... を経由してユーザーを攻撃者の origin に飛ばす経路として悪用できる状態だった。

確認項目

  • CI green (新規 TestSanitizeReturnURL を含む)。
  • Manual: curl -i "localhost:8080/login?return_url=javascript:alert(1)" → form action / hidden field の値が / になり、payload が出力されないこと。

The previous filter accepted url-parseable inputs whose Host was empty,
which lets through "javascript:alert(1)" and "/\evil.com" — the former
is opaque (Host empty) and the latter normalizes differently in browsers
than url.Parse expects, both classic open-redirect vectors. Require the
input to start with a single "/" and reject any URL whose Scheme,
Host, or Opaque is set.

Assisted-by: Claude (model: claude-opus-4-7)
@anko9801 anko9801 requested a review from saitenntaisei as a code owner May 5, 2026 15:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Warning

Rate limit exceeded

@anko9801 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 4 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f351a67-f17a-4be1-b9b3-137d1f345714

📥 Commits

Reviewing files that changed from the base of the PR and between 003c323 and e40d6cf.

📒 Files selected for processing (2)
  • internal/router/v1/auth.go
  • internal/router/v1/auth_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sanitize-return-url-strict

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.

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.

1 participant