Repository navigation
Description
Problem
src/lib/auth.ts stores the session JWT in window.localStorage under mergefi_token, read by apiRequest in src/lib/api.ts and attached as a bearer token to every authenticated call (claim bounty, fund escrow, deposit to maintenance pool). This is a classic XSS-to-account-takeover vector: any script injection anywhere in the app (a maintainer-controlled issue body is rendered from GitHub-sourced content via raw.issue?.body in adaptBounty — check how/where description is rendered on /issues/[id]) could exfiltrate the token and impersonate the user for wallet-adjacent financial actions. There is no CSP configured in next.config.ts, no token expiry/refresh flow visible in AuthContext.tsx (refresh() just clears the token on any /auth/me failure, with no distinction between "expired, try refresh" and "invalid, log out"), and no rotation on privilege-sensitive actions like wallet connection.
Why this is hard
- You need to actually verify whether GitHub issue bodies are rendered as raw HTML/markdown anywhere in the issue detail page (
src/app/issues/[id]/page.tsx) or if they're currently escaped — this determines whether the XSS vector is theoretical or live, and the fix differs materially in each case. - Migrating off localStorage to httpOnly cookies requires backend cooperation (the
mergefi-backendrepo issues the JWT) — scope what's achievable frontend-only (CSP hardening, token scoping, short-lived tokens with silent refresh) versus what must be filed as a cross-repo dependency, and design the frontend to work with either. - Next.js 16 App Router CSP setup via
next.config.tsheaders needs to account for Turbopack dev mode's inline scripts/HMR websocket, Freighter's content-script injection model, and any inline styles Tailwind v4's JIT might need — getting this wrong breaks dev or breaks the wallet extension bridge. AuthContext.refresh()currently has no retry/backoff and clears the token on ANY failure from/auth/me, including transient network errors — meaning a flaky connection silently logs the user out. Distinguishing "token invalid" (401) from "network blip" (fetch failure) requires inspectingapiRequest'sApiRequestErrorvs a generic throw, which the current code doesn't do.
Scope
- Audit and fix any unescaped rendering of GitHub-sourced content (issue titles/bodies/labels) across
/issues,/issues/[id],/milestones. - Add a CSP header in
next.config.tsscoped as tightly as possible while preserving Turbopack dev and Freighter compatibility. - Fix
AuthContext.refresh()to only clear the token on a genuine 401/403, retrying with backoff on network failures. - Document (in the PR) the localStorage-to-cookie migration path as a follow-up, including what backend changes it requires.
Acceptance criteria
- A crafted issue body/title cannot execute script in the rendered page.
- A CSP header is present and doesn't break
npm run devor Freighter connect/sign flows. - Transient network failure during
/auth/meno longer logs the user out.
Activity
Biokes commentedon Aug 25, 2026
@Biokes has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Biokes to this issue.
luciachizaram commentedon Aug 25, 2026
@luciachizaram has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @luciachizaram to this issue.
drips-wave commentedon Aug 25, 2026
Congratulations, @luciachizaram! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.
🧑💻 @luciachizaram: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
Warning
When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
fix(security): add CSP header and retry auth refresh on network errors
test: add tests for auth retry, idempotency keys, and decimal-safe he…
grantfox-oss commentedon Aug 25, 2026
🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!
@luciachizaram's PR #333 was approved and merged by @chonilius.
🏆 @luciachizaram: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (990 total points). Track your full progress on GrantFox.
👏 Great work, @luciachizaram! Keep contributing to MergeFi.
drips-wave commentedon Aug 25, 2026
This issue has been completed by @luciachizaram as part of the Stellar Wave Program's 8th Wave 🥳
😎 @luciachizaram: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.
Fix: Wire up smart-polling/claim-race, Tabs a11y, request timeout, CS…