fix(web): sanitizeHref hardening + API path-segment encoding#96
Merged
Conversation
Security findings from cora scan (web/): - utils.sanitizeHref: reject backslash (browser normalizes `\`→`/`, so `/\\evil.com` became protocol-relative `//evil.com` off-site redirect) and strip ASCII tab/newline/CR before checking (browser ignores them, allowing scheme smuggling like `java\tscript:`) - api/client: encodeURIComponent every path segment (slug/id/postId/ provider) to prevent path traversal via `..` reaching unintended routes (e.g. `/api/projects/../auth/me`) - board/[slug]: move `initialized` declaration above onMount (TDZ smell — used at line 84, declared at 179); simplify 'v' vote shortcut to a single auth guard - tests: sanitizeHref backslash + tab-smuggling cases
🔍 Cora AI Code Review🟡 Warning (1)
Review powered by cora-cli · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the valid security findings from
cora scanin the frontend (web/).Fixed
utils.tssanitizeHref\→/, so a relative-looking/\\evil.comresolved to protocol-relative//evil.com(off-site redirect)utils.tssanitizeHrefjava\tscript:could slip a dangerous scheme past the check[\t\n\r]before validatingapi/client.ts/api/projects/${slug}), so..could reach unintended routes (/api/projects/../auth/me)encodeURIComponentevery path segment via aseg()helperBug fixes (same files)
board/[slug]/+page.svelte:initializedwas referenced inonMount(line 84) before its declaration (line 179) — moved the declaration aboveonMountto remove the TDZ smell.board/[slug]/+page.svelte: thev(vote) shortcut had convoluted/redundant auth logic — simplified to a singleif (!authed) return;(matches the shortcut registry, wherevisauthRequired: true; Rungu has no anonymous voting).Triaged as false positive
toggle_voterequiresCurrentUserbackend-side, andvis registeredauthRequired: true). Not applicable.Out of scope (separate concerns)
AttachmentGallerysequential uploads,CommentThreadunbounded recursion, board search-debounce timer patternChecklist