Track 09 · Lesson 7 of 9Shipping safely

Track 09 · Shipping safely

Leaks through URLs and logs

Lesson 7 of 9· 6 min

Anything in a URL is copied everywhere the URL goes: browser history, server and proxy logs, analytics, error reports, and sometimes the Referer sent to other sites. Tokens in URLs leak quietly, long after launch.

Follow a reset token

Every place the URL is copied

The link in the email

https://app.example.com/reset?token=8f3kQ2vX
  • Browser history

    every visited URL is kept

    Has the token
  • Your server’s access log

    logs the full request line

    Has the token
  • CDN and proxy logs

    every hop can log it

    Has the token
  • Referer sent to another site

    an old Referrer-Policy sends the full URL

    Has the token
  • Analytics pageview

    the SDK records the URL on load, before your code runs

    Has the token
  • Error tracker reports

    errors during load carry the full URL

    Has the token
  • Third-party chat widget

    reads location.href like any script

    Has the token
The token sits in 7 places you don’t control, for as long as each keeps its logs. Single-use, short-lived tokens limit the damage; cleaning the URL limits the copies.

Read it, then clean it#

Reset, invite and magic-link tokens often have to arrive in a link. The page should read the token, keep it in memory, and immediately replace the URL with a clean one using history.replaceState. Then send the token in a request body, never in another URL.

Try it on this page

Your real address bar

const token = new URLSearchParams(location.search).get("token")
history.replaceState(history.state, "", location.pathname)
// keep `token` in memory and POST it; never put it back in a URL

location.href, right now (look at your address bar too)

Press the first button.

The other copies#

  • Fragments (#token=…) are never sent to servers or included in Referer, which removes the log copies.
  • Configure your error tracker and analytics to strip query strings before sending.
  • Redact tokens in proxy and CDN log formats.
  • Keep link tokens single-use and short-lived, so the copies that do survive are useless.

In a code review

LowFrontend + DevOps

Tokens in URLs, logs and analytics

Fix: Strip tokens with history.replaceState after reading, scrub query strings before sending telemetry, redact tokens in proxy logs.

0 of 4 checked

Check yourself

Why does history.replaceState help after reading a token?