FIX: URL sanitization to handle schemeless credentials#37440
FIX: URL sanitization to handle schemeless credentials#37440wxiaoguang merged 18 commits intogo-gitea:mainfrom
Conversation
|
Theoretically speaking, if you have introduced the new regexp, then you don't need to keep the old algorithm |
yep just had a look at it again and that also makes it easier |
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
@silverwind why you remove the % ?? |
|
Because it was duplicate in the |
|
Found some edge cases, I think regexp is not easy to be right. Will try to improve. |
There was a problem hiding this comment.
Pull request overview
This PR addresses credential exposure risks by improving URL/userinfo sanitization so that credential-like substrings (including schemeless user:token@host forms seen in git stderr) are masked before being surfaced in logs/UI errors.
Changes:
- Sanitize
repo.CloneURLbefore logging during repository migration. - Rework
util.SanitizeCredentialURLsto mask schemeless credential patterns and update the masking placeholder. - Update/add unit tests and expand git command log sanitization coverage for schemeless
a:b@cpatterns.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
services/migrations/migrate.go |
Sanitizes the clone URL before trace logging during migration. |
modules/util/sanitize.go |
Updates sanitization logic to catch schemeless credential patterns and standardizes the placeholder. |
modules/util/sanitize_test.go |
Adjusts/adds test cases for the updated sanitization behavior. |
modules/git/gitcmd/command.go |
Ensures arguments are passed through the sanitization routine when building debug log strings. |
modules/git/gitcmd/command_test.go |
Updates expectations for the new placeholder and adds coverage for schemeless a:b@c/. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Consume "[...]" IP-literals as a single host token. The previous switch arms for `[`/`]` were dead: at `sepAtPos+1` the `[` fell through, and the next `:` broke the host loop. Output looked correct only because the unparsed tail was appended verbatim. - Replace the fast path's `sepColPos > sepAtPos` check (which used only the first `@` and `:`) with an existence test on both. Lines containing a `git@host:path` SSH URL followed by a credential URL were skipped. - Add tests for `[2001:db8::1]:8080`, multi-URL with `[::1]`, unmatched `[`, and SSH-URL-then-HTTPS. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
@wxiaoguang check 69003ad please. |
* main: Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) Fix scheduled action panic with null event payload (go-gitea#37459) Fix attachment Content-Security-Policy (go-gitea#37455) [skip ci] Updated translations via Crowdin Rename CurrentRefPath to CurrentRefSubURL (go-gitea#37453) Clean up org pages layout (go-gitea#37445) Fix script error alert (go-gitea#37458) Fix inconsistent disabled styling on logged-out repo header buttons (go-gitea#37406) Add API endpoint to reply to pull request review comments (go-gitea#36683) Add CurrentURL template variable back (go-gitea#37444)
Fixes #37435