Prevent redirect bypasses via backslash-encoded paths#36660
Prevent redirect bypasses via backslash-encoded paths#36660silverwind merged 10 commits intogo-gitea:mainfrom
Conversation
|
Review by @silverwind, written with Claude Code. Looks correct. The fix addresses open redirect via backslash normalization: browsers can normalize With the new blanket backslash check, the backslash cases in the old prefix check on line 24 ( if len(s) >= 2 && s[0] == '/' && s[1] == '/' {
return false
}Other observations:
The PR description is empty — it would be good to mention this is a security fix for open redirect via backslash normalization, for changelog/backport purposes. |
I'm sorry but such reviews are unactionable. You need to at least give some hint what you feel is wrong. |
I can only see you copy-paste the AI response. Since you have approved, can you answer the questions?
|
|
@silverwind @lunny , you see, even if I explained, there is no progress. Why should I waste time on explaining? That's why I only say "wrong" to the people who don't understand the problem and never learn from lessons. |
|
I would help if the PR description contains some actual reasoning for the change or a link to the security report it relates to. |
|
I will continue the work. Thank you for the review. |
This one will not, I removed it from test.
%5c will be decoded to \ and the whole string will be considered as
I think it might that Web browsers thinks
The code will be used on |
|
Still, completely wrong. If 1 doesn't, why 2 does? Are you able to reproduce in 3 Have you read code for 4? What if The logic itself is wrong. Really curious that whether you use your brain when you write code. |
@silverwind @lunny the questions are still not addressed |
Check u.Path (parsed, decoded path component) for backslashes instead of checking the raw string for literal backslashes or %5c. This avoids false positives on query parameters while correctly catching path traversal attacks like "/a/../\example.com" that browsers can normalize to "//example.com" (protocol-relative open redirect). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Written by @silverwind using Claude Code. I pushed a reworked fix to the branch that addresses wxiaoguang's feedback. The key issues with the previous approach:
The new approach: Check
Test cases include both exploit vectors ( |
|
Proper fix applied and added test cases so this does not reject valid backslashes in query. |
What's wrong? Have you read the new code? |
|
Your |
Can you stop guessing or imagining? How slow it could be? Have you benchmarked it? |
I just reset all files from previous commit, because the code need to be rewritten with comments, the tests can be simplified and focused. What's wrong? |
There is a slight difference in the implementations in golang, but practically not meaningful.
More test cases are always valuable imho so you can be sure the implemenation catches all edge cases. |
Show me, what edge cases. Don't just guess. |
|
Your tests validate the same as mine. That's fine but you could have just mentioned that and we save this whole discussion. |
But why you don't read code but only guess? |
|
I saw you reverting my stuff and then I compared the tests only in a fleeting fashion. |
This change tightens relative URL validation to reject raw backslashes and `%5c` (encoded backslash), since browsers and URL normalizers can treat backslashes as path separators. That normalization can turn seemingly relative paths into scheme-relative URLs, creating open-redirect risk. Visiting below URL to reproduce the problem. http://localhost:3000/user/login?redirect_to=/a/../\example.com http://localhost:3000/user/login?redirect_to=/a/../%5cexample.com --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Backport #36660 by @lunny This change tightens relative URL validation to reject raw backslashes and `%5c` (encoded backslash), since browsers and URL normalizers can treat backslashes as path separators. That normalization can turn seemingly relative paths into scheme-relative URLs, creating open-redirect risk. Visiting below URL to reproduce the problem. http://localhost:3000/user/login?redirect_to=/a/../\example.com http://localhost:3000/user/login?redirect_to=/a/../%5cexample.com Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This change tightens relative URL validation to reject raw backslashes and
%5c(encoded backslash), since browsers and URL normalizers can treat backslashes as path separators. That normalization can turn seemingly relative paths into scheme-relative URLs, creating open-redirect risk.Visiting below URL to reproduce the problem.
http://localhost:3000/user/login?redirect_to=/a/../\example.com
http://localhost:3000/user/login?redirect_to=/a/../%5cexample.com