Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

Users report that magic login links 'already used' errors appear on first click, mostly for corporate email addresses. What is going on and how do you fix it?

Corporate email security scanners and link previewers open every link in an incoming email before the user sees it, and if our link redeems the single-use token on a GET, the scanner uses it up. The fix is to make the link open a page where the user must press a button, which sends a POST that redeems the token; scanners fetch pages but do not submit forms. We can also bind the token to the browser that asked for it or send a code to type, keep tokens short-lived, and log each redemption with its user agent to confirm the cause.

Why this question is asked

This is a classic 'works on my machine' bug: every developer tests with a personal inbox and the link works, while customers at large companies complain that the link is already used the first time they click it. Interviewers ask it because it rewards thinking about what else touches a link besides the user. In this answer, we will look at the clue in the report, find the hidden visitor, confirm it with logs, apply the main fix, and add the extra protections that make the flow robust.

1Reading the Clue in the Report

Two details in the report point the way. The error says the token was already used, so someone redeemed it before the user. And it happens mostly for corporate email addresses, so the extra visitor lives in corporate email systems, not in our application. A bug in our token code would hit all users equally; a pattern by email domain says something sits between our email and the user.

2The Hidden Visitor: Email Scanners and Link Previewers

Many companies run email security gateways that protect staff from phishing. When an email arrives, the gateway rewrites or follows every link and fetches the target page to check it for malware, often seconds after delivery and before the user opens the message. Chat tools and some email clients do something similar to build link previews.

If our link is something like /login/magic?token=8f3c... and the server redeems the token as soon as it receives a GET for that URL, the scanner's fetch logs the scanner in, the token is deleted, and the real user's click a minute later finds nothing. The scanner throws away the session cookie it received, so nobody actually gets into the account, but the user is stuck.

Step throughHow the scanner consumes the token
ApplicationEmail scannerUser's browser
email with GET link containing the token
GET /login/magic?token=8f3c (automatic check)
token valid: redeem and delete it
200, logged in session (discarded)
GET /login/magic?token=8f3c (real click)
already used

6 messages in order. Play them, or step through them one at a time.

The scanner was simply checking the link for malware; redeeming on GET turned that into a login.

3Confirming It in the Logs

Before changing anything we prove the theory. We log every token redemption attempt with the time, the result, the IP address and the User-Agent header, without logging the token itself. For an affected user we expect to see a successful redemption a few seconds after the email was sent, from an IP address in a cloud or security vendor range and with a User-Agent that is not the user's normal browser, followed by a failed attempt from the user's real browser.

Java
log.info("ott redeem user={} result={} ip={} ua={} age_ms={}",
username, result, request.getRemoteAddr(),
request.getHeader("User-Agent"), Duration.between(token.getCreatedAt(), now).toMillis());
// ott redeem user=anna@corp.example result=SUCCESS ip=52.x.x.x ua=Mozilla/5.0 (compatible; scanner) age_ms=2140
// ott redeem user=anna@corp.example result=ALREADY_USED ip=81.x.x.x ua=Mozilla/5.0 (Macintosh; ...) age_ms=95310

A first redemption two seconds after sending, from a data-centre address, is the signature. Real people do not open an email and click a link within two seconds of delivery.

4The Fix: Redeem Only on a POST From a User Action

The rule that fixes this is the rule HTTP already sets: GET requests should not change state. So the link only opens a page. The page shows a short message and a button such as 'Sign in as anna@corp.example', with the token in a hidden form field. Pressing the button sends a POST, and only the POST redeems the token. Scanners fetch pages and may follow redirects, but they do not press buttons and submit forms, so the token survives until the user clicks.

XML
<!-- GET /login/ott?token=8f3c... only renders this page, the token is still unused -->
<form method="post" action="/login/ott">
<input type="hidden" name="token" value="8f3c...">
<input type="hidden" name="_csrf" value="...">
<button type="submit">Sign in</button>
</form>
<!-- POST /login/ott redeems the token and logs the user in -->
Step throughRedeeming safely
  1. GET the linkrender a page with a button; token untouched
  2. User presses Sign inPOST with the token and CSRF value
  3. Token found, unexpired, unused?
    YesDelete it and log the user inNoShow 'link expired, send a new one'

3 steps in order. Play them, or step through them one at a time.

Spring Security's built-in one-time token login, available since 6.4, already works this way: opening the link shows a sign-in page and the token is submitted with a POST to /login/ott. So if our application has a home-grown magic-link endpoint that redeems on GET, moving to the built-in support is itself a fix (check your version for the exact default pages).

5Extra Protections Worth Adding

We can go further. Binding the token to the browser that requested it means storing, at generation time, a random value in a cookie on the requesting browser and checking it at redemption. Then even a scanner that submits forms cannot use the token, because it does not have the cookie. The cost is that a user who requests the link on a laptop and opens the email on a phone is refused, so we need a clear message and an easy way to request a new link on the phone.

Another option is to send a short code instead of a link, which the user types on the page where they asked for it. A scanner has nothing to click. Codes need stricter attempt limits because they have fewer possible values, for example five attempts per code.

Whatever we choose, tokens stay short-lived, around five minutes, and single use, and we keep the redemption logging so we can see quickly if a new scanner behaviour appears.

6Follow-up questions

Could we just allow the token to be used twice?

That would let the scanner and the user both log in, but it also means that anything which fetches the link, including a scanner that keeps the session, gets a working login. Weakening single use to work around a design flaw trades a support problem for a security one.

Why not block scanner user agents?

Scanners change their User-Agent, many pretend to be normal browsers, and new ones appear all the time. A rule list would always be one step behind. Requiring a POST works for every scanner without knowing which one it is.

Do password reset links have the same problem?

Yes, any single-use link that acts on GET does. Reset links usually show a form to choose the new password, so the token is only used on the POST, which is why they suffer less. Email confirmation links should follow the same pattern.

7Conclusion

In this answer, we traced 'already used' errors on first click to email security scanners and link previewers that fetch links before the user does, consuming tokens that were redeemed on GET. We confirmed it with redemption logs showing data-centre requests seconds after sending, fixed it by making the link render a page whose button sends a POST to redeem the token, and added options such as binding the token to the requesting browser or using a typed code, while keeping tokens short-lived and logged.

What to say in the interviewAbout 90 seconds aloud

Open with

The pattern by email domain tells me something between our email and the user is clicking first. Corporate email security gateways, and link previewers in some clients, fetch every link in incoming mail to scan it, usually seconds after delivery.

Then, if they want more

If our magic link redeems the single-use token on a GET, the scanner's fetch consumes it, and the real click a minute later gets already used.

I would confirm it by logging each redemption attempt with time since generation, IP and user agent, never the token itself; I expect a successful redemption within a few seconds from a data-centre IP with an unusual user agent, followed by the user's failed attempt.

The fix is to stop changing state on GET: the link opens a page with a sign-in button and the token in a hidden field, and only the POST from that button redeems it. Scanners fetch pages but do not submit forms.

Spring Security's built-in one-time token login already works this way since 6.4, so moving to it may be the simplest fix. Optionally I would bind the token to the browser that requested it with a cookie, or send a code the user types, accepting the cross-device cost.

Tokens stay short-lived and single use, and I keep the redemption logs to spot new scanner behaviour.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Users report that magic login links 'already used' errors appear on first click, mostly...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/917d3c141c/