Skip to content

feat: /go/ redirect map v1 (TASK-25176) - #4195

Open
0xkkonrad wants to merge 3 commits into
devfrom
feat/TASK-25176-go-redirect-map
Open

0xkkonrad wants to merge 3 commits into
devfrom
feat/TASK-25176-go-redirect-map

Conversation

@0xkkonrad

@0xkkonrad 0xkkonrad commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Konrad wants short links on peanut.me/go/ that he can read and add by editing one file. This adds GO_REDIRECTS in src/features/tracked-links/go-map.ts: a hardcoded map from the path after /go/ to a path on peanut.me. The /go/[slug]/[[...rest]] page checks the map first and answers a 307 on a hit. On a miss, the creator username engine runs unchanged.

  • Key: everything after /go/, lowercased, trailing slash ignored, segments of a-z 0-9 - _. Exact match only: /go/app/x is a miss.
  • Destination: a path on peanut.me that starts with / and is not /go or below it. A jest test checks every line, and the resolver checks again at request time. A bad line is a miss, so it falls through to the username engine.
  • The lookup uses an own-property check, so constructor or __proto__ never match.
  • The incoming query string is dropped on a mapped path, utm_* tags included. The creator redirect differs: it forwards the cleaned utm_* tags. To tag a short link, put the tags in its destination.
  • generateMetadata skips the creator API lookup on a mapped path.
  • Seed entry: app → /app (the smart store link). No account can hold app: it is in the API's reserved routes. No entries for konrad/1–3: the Palermo posters stay on the username engine until Konrad decides.
  • No click event in v1. No docs in peanut-ui; the spec is mono engineering/ui/tracked-links.md § Redirect map, linked from the go-map.ts header.

Task

TASK-25176: https://www.notion.so/41e83811757981988850f65f7d2dc056

How to add a redirect

Add one line to GO_REDIRECTS in src/features/tracked-links/go-map.ts, for example 'lisbon/flyer': '/en/send-money-to/brazil?utm_source=flyer',.
go-map.test.ts fails CI on a full URL, another host, a /go/ destination, an upper-case or invalid key, or a key that redirects.json takes first.

Risks

  • A map key wins over a creator username on the same path. Only the exact mapped path: a promo/flyer key leaves /go/promo and /go/promo/ig on the creator engine. A one-segment key such as konrad would take over that creator's bare link, so check a key against live usernames before you add it.
  • Unmatched paths fall through to the username engine. The spec marks this as an assumption: Konrad said "go ahead" on a draft that recommended it, but has not confirmed it explicitly. The alternative is a 404 on a miss.
  • Six keys can never reach the map in production. next.config.js runs redirects.json before this page. Its /:locale/<x> rules answer /go/team, /go/blog, /go/deposit/via-avalanche, /go/withdraw/avalanche, /go/deposit/from-faster-payments and /go/deposit/from-spei with a cacheable 308. Creator usernames already had this. go-map.test.ts fails on such a key. next dev does not load those rules. Constraining :locale in those rules is a separate change.
  • "Own domain" covers the first hop only. Some peanut.me paths are forwarded off-site by fixed redirects.json rules: /events, /pints, /foodie, /seedlings, /packet, /create-packet, /batch/*, /raffle/*. A map line pointing at one of them passes both checks, and the visitor ends on luma.com, GitHub or Notion. The hosts are fixed, so this is not an open redirect.
  • Blast radius: one early return in the page and one guard in generateMetadata. A miss runs the old code path.

QA

Preview for this head: P=https://peanut-wallet-oas5l05f5-squirrellabs.vercel.app. Production answers 404 for every mapped path until release. Each command is a GET that does not follow redirects: c() { curl -s -o /dev/null -D - "$P$1" | grep -iE '^(HTTP|location)'; }.

  • c /go/app → 307, location: /app
  • c /go/APP/ and c '/go/app?utm_source=x&foo=bar' → 307, location: /app (case and trailing slash ignored, query dropped)
  • c /go/app/x → 404 (exact match only)
  • c /go/konrad/1 → 307, location: /home?app_entry=1&tl=konrad&acq_invite=konrad&tl_s=1, the same as production today (also /2, /3, /ig)
  • c '/go/konrad?utm_source=instagram&utm_campaign=x&foo=bar' → 307, location: /home?app_entry=1&tl=konrad&acq_invite=konrad&utm_source=instagram&utm_campaign=x, the same as production
  • c /go/nonexistentuserzz9, c /go/constructor, c /go/__proto__ → 404
  • c /go/team → 308, location: /go/press (the redirects.json rule above; the same on production)

Use a real username without a creator page, such as konrad. A creator with a creator page (juanacervio) answers 404 on the preview because the preview API does not have that user; the dev preview without this PR shows the same 404.

Design notes / accepted trade-offs

  • The own-domain check is a small local function, not sanitizeRedirectURL from src/utils/cookie-url.utils.ts. That module imports @/utils/sentry-lazy, which imports posthog-js at the top level. The local check keeps the browser analytics SDK out of the /go/ page's import graph. It is not identical: it parses against TRACKED_LINK_ORIGIN, requires the same origin and no credentials, and refuses a decoded path that starts with // or /\ or that is /go or below. It does not repeat sanitizeRedirectURL's final re-parse, so a hand-written destination such as /%09/evil.com passes. Destinations come only from the hardcoded map, never from the request, and the emitted Location stays on peanut.me, so this is accepted for v1 and listed as a follow-up.
  • Test-only seams: resolveGoRedirect takes an optional map (default GO_REDIRECTS) so the bad-destination cases run against fixtures. Tests also run every live entry through that lookup.

Verification

  • Local gate on boat.dev (head 76ed7e58f, source hashes matched the worktree): tsc --noEmit exit 0; jest src/features/tracked-links 10/10 suites, 235/235 tests; eslint on the changed files exit 0; prettier unchanged. Full build not run locally (sandbox disk full); CI built the preview.
  • Mutation tests (each restored afterwards): a full-URL, /go/, upper-case or %2F%2F entry; a team key; removing the own-property guard; moving the lookup below the username check; generateMetadata checking [slug] only; an empty default map; the page passing an empty map. Each made at least one test fail.
  • Lens review: adversarial review by spec, next-runtime, test-quality, simplicity and PR-hygiene lenses, with two fix rounds: 12 findings fixed in db3c2c292 and 76ed7e58f (tests, header comment, PR body). A final pass found the re-parse gap above (kept as a design note) and two wording nits, fixed in this body.
  • Live probe: the QA paths above on the preview of 76ed7e58f and on production; all unmapped paths matched production except juanacervio (explained above). Open-redirect inputs (/go/%2F%2Fevil.com, /go/%5C%5Cevil.com, query-carried URLs) stayed same-origin.
  • CI: ci-success (the only required check) green on 76ed7e58f, with all 12 jobs it needs. Unit: 22,792 tests, 0 failed. Non-required i18n-overflow was still running; it runs about 45 minutes on other branches today too.
  • Chip: review on 76ed7e58f: no blocking findings, 0 findings. 0 review threads.
  • Not verified: e2e/flows/go-links.spec.ts (CI skips it) was not run, so the creator-page arm has jest coverage only. Production robots headers on a mapped 307 are not checked.

Screenshots: N/A (no visible change)

Konrad wants short links on peanut.me/go/ that he can add by editing one
file. A mapped path answers a 307 before the creator username engine runs;
every destination must be a same-origin path outside /go/, checked by a
test and again at request time, so a bad line can never send visitors off
peanut.me or into a loop. Seeded with app -> /app, which no username can
hold.

TASK-25176
@notion-workspace

Copy link
Copy Markdown

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
peanut-wallet Ready Ready Preview Nov 20, 2026 6:35pm UTC

Request Review

@0xkkonrad

Copy link
Copy Markdown
Contributor Author

/chip review

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 11169.33 → 11174.16 (+4.83)
Findings: +1 net (+4 new, -3 resolved)

🆕 New findings (4)

  • medium complexity — src/app/go/[slug]/[[...rest]]/page.tsx — CC 19, MI 52.63, SLOC 106
  • medium complexity — src/features/tracked-links/go-map.ts — CC 10, MI 62.26, SLOC 27
  • low high-mdd — src/app/go/[slug]/[[...rest]]/page.tsx:49 — GoPage: MDD 10.2 (uses across many lines from declarations)
  • low missing-return-type — src/app/go/[slug]/[[...rest]]/page.tsx:49 — GoPage: exported fn missing return type annotation

✅ Resolved (3)

  • src/app/go/[slug]/[[...rest]]/page.tsx — CC 17, MI 53.79, SLOC 97
  • src/app/go/[slug]/[[...rest]]/page.tsx:47 — GoPage: MDD 10.8 (uses across many lines from declarations)
  • src/app/go/[slug]/[[...rest]]/page.tsx:47 — GoPage: exported fn missing return type annotation

📈 Painscore deltas (top movers)

File Before After Δ
src/features/tracked-links/go-map.ts 0.0 4.5 +4.5

@chip-peanut-bot chip-peanut-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chip review — no blocking findings — this is not an approval

No findings in the pinned redirect-map change.

Checked clean

  • Exact head and base merge-base verified; PR description and four-file diff reviewed.
  • Mapped /go/app redirects to the existing /app smart-store route; unmapped paths retain creator lookup and handoff.
  • Destination validation rejects cross-origin, decoded protocol-relative, and /go loop paths; own-property lookup avoids inherited keys.
  • No visual design-system change. Typecheck, lint, format, and ds-lint passed at this SHA; unit, SEO contract, and native-export checks were still in progress when reviewed. Local dependencies were absent, so tests were not rerun.

Security review: did not run — this change has no security, privacy or money surface, so it was not asked. This review is one reviewer short.

Third opinion by claude-opus: 0 finding(s), marked with the model name. It answers only product truth, missing tests and the cross-repo contract, so treat its findings as advice.

Copy check by claude-haiku-5-5: 0 finding(s), titled "Copy now wrong". Every quoted passage was checked against the file.

Exact head: c7f762c13a4e · Context: repo, design, api · Took 2m (queued 1m)

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • ✅ unit: 22792 ran, 0 failed, 0 skipped, 12.2m

📊 Coverage (unit)

metric %
statements 88.8%
branches 82.2%
functions 83.4%
lines 90.4%
⏱ 10 slowest test cases
time test
🐢 38.6s scripts/__tests__/screens-adapter.test.js › runs the existing synthetic screen adapter Node acceptance suite
🐢 20.9s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with pointer
🐢 19.6s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with Enter
🐢 16.8s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › keeps unavailable Argentina searchable and opens its residence explanation with Space
🐢 10.3s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › preserves ordinary Argentina selection for residence null
🐢 10.0s src/features/deposit-accounts/__tests__/AddMoneyArgentinaCountry.acceptance.test.tsx › preserves ordinary Argentina selection for residence AR
🐢 9.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › Network failure keeps loading while retries remain, then shows the generic error
🐢 7.4s scripts/__tests__/signup-attribution-paths.test.ts › includes newly published articles and locale fallbacks without editing the manifest
🐢 7.0s scripts/__tests__/indexable-urls.test.ts › excludes missing locale files, drafts, redirects, and retired pages from crawl and submission lists
4.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › User KYC not approved fails fast with copy that names the real cause
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

…order

In production next.config.js runs redirects.json before the /go/ page, and
its /:locale/<x> rules match /go/team, /go/blog and four deposit/withdraw
paths with a 308. A map key with one of those names would never redirect,
so go-map.test.ts now fails on it and the header names the taken keys.

Also: the entry test names the bad key, a test covers inherited keys, and
routes tests pin that the lookup runs before the username check (dashed
keys) and that metadata skips the creator lookup for multi-segment keys.
The header example now points to a page that exists and links the spec.
The entry check called goRedirectDestination directly and the routes mock
dropped any map the page passed, so CI stayed green if the default map or
the page stopped using GO_REDIRECTS. Resolve every live key through
resolveGoRedirect and let the mock forward a passed map.
@0xkkonrad

Copy link
Copy Markdown
Contributor Author

/chip review

@chip-peanut-bot chip-peanut-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chip review — no blocking findings — this is not an approval

No findings in the pinned redirect-map change.

Checked clean

  • Verified the new head and exact dev merge-base; reviewed the two follow-up commits and the full four-file PR diff.
  • Live-map lookup, own-property guard, same-origin destination validation, and legacy creator fallback remain consistent with the PR's explicitly limited v1 behavior.
  • The new tests cover actual map entries, redirect-rule precedence, a dashed key, metadata lookup bypass, and an inherited key.
  • Read the newer mono tracked-links redirect-map spec: it describes a broader future replacement, while this PR explicitly retains the legacy fallback and same-origin v1 scope.
  • At review time, this SHA had a successful preview deployment and backdoor scan; the unit/typecheck checks had not yet appeared in its check-run list.

Security review: did not run — this change has no security, privacy or money surface, so it was not asked. This review is one reviewer short.

Third opinion: did not run — it reads only the first review of a pull request; the first reviewer checks later rounds. This review is one reviewer short.

Copy check by claude-haiku-5-5: 0 finding(s), titled "Copy now wrong". Every quoted passage was checked against the file.

Exact head: 76ed7e58ff77 · Context: repo, engineering, design · Took 2m

@0xkkonrad
0xkkonrad marked this pull request as ready for review November 20, 2026 18:59
@github-actions

Copy link
Copy Markdown
Contributor

English · 5 not comparable

Open screen library dashboard

Review preview: e06be1a → 76ed7e5. Incomplete capture; unavailable states are listed in the report. Other locales were not captured; add the screens:all-locales label and re-run Screen library to include them.

Screen Library coverage: review — UI review needs a complete, unique comparison for every required locale.

Screen Library copy: review — 3 baseline entries are now shown or deleted; remove from scripts/screens/copy-coverage-baseline.json: card.yourCard.redZone, paymentLoading.sayingHola, profile.unlockPayments.chips.attention. Add a capture state that shows the copy, or add the keys to the baseline with “Screen Library copy exception: ” on its own line in the PR description. Copy coverage: 1318/4069 keys shown.

This branch was successfully deployed

1 active deployment
Preview — 76ed7e58 Deployed Nov 20, 2026 by vercel[bot]
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