JWT Signing Process Servers generate JWTs by encoding a header and payload (claims like user ID) in Base64, then signing a hash of them using HMAC-SHA256 (or similar) with a strong, secret key. The signature verifies the token hasn’t been altered; invalid signatures cause rejection. This doesn’t hide data—use HTTPS and avoid sensitive info in payloads . Securing Cookies for JWTs Set cookies with these flags on the server: • HttpOnly: Blocks JavaScript access, mitigating XSS theft. • Secure: Ensures transmission only over HTTPS, preventing MiTM interception. • SameSite=Strict/Lax: Stops CSRF by restricting cross-site requests. Example in Node.js:  res.cookie('token', jwtToken, { httpOnly: true, secure: true, sameSite: 'Strict', maxAge: 3600000 })  . Extra Protections Use short expiration times and refresh tokens stored separately in memory or secure cookies. Enforce HSTS headers for HTTPS-only. Regularly rotate secret keys and validate inputs --------------------------------------------------------------------------------------------------------------------------------- Protecting "remember me" login tokens (often JWTs or session tokens) from manual copying or theft requires server-side controls and cookie attributes that limit client-side access and bind tokens to specific contexts. No method fully prevents a determined user from copying a token via browser dev tools, but mitigations reduce usability and impact of stolen tokens. Key strategies focus on HttpOnly cookies, token rotation, and device/user binding [1][2]. ## Core Cookie Protections Use server-set cookies with restrictive flags to block JavaScript access and network interception: - *HttpOnly*: Prevents document.cookie or JS from reading the token, stopping XSS theft and casual copying. - *Secure*: Limits transmission to HTTPS only. - *SameSite=Strict*: Blocks cross-site usage, invalidating copied tokens in other contexts. These make manual extraction harder without server logs or proxy tools [2]. ## Token Design Best Practices Implement these to render stolen tokens short-lived or unusable: - *Short-lived access tokens* paired with long-lived refresh tokens in separate HttpOnly cookies; rotate refresh tokens on each use, invalidating the old one. - *Device fingerprinting*: Bind tokens to browser fingerprints (e.g., user-agent, IP, screen resolution) hashed into the token payload; validate on server. - *Nonce or one-time use*: Store token hashes server-side; invalidate after first use or on logout. Example: On "remember me" login, generate a signed token with user ID, expiration, and device hash [1][3]. ## Server-Side Defenses - *Revocation lists*: Store active tokens in a database; check and delete on use or suspicious activity. - *Rate limiting and monitoring*: Flag multiple uses from new IPs/devices; force re-authentication. - *Password change invalidates all*: On password reset, purge related remember-me tokens server-side. Combining these minimizes risks even if a token is copied [2][4]. Sources [1] How to build (and how not to build) a secure “remember ... https://news.ycombinator.com/item?id=5969932 [2] Implementing Secure "Remember Me" with Refresh ... https://leapcell.io/blog/implementing-secure-remember-me-with-refresh-tokens-in-javascript-applications [3] Remember-Me Authentication :: Spring Security https://docs.spring.io/spring-security/reference/servlet/authentication/rememberme.html [4] 18. Remember-Me Authentication - Spring https://docs.spring.io/spring-security/site/docs/5.0.x/reference/html/remember-me.html [5] How to build (and how not to build) a secure “remember me ... https://www.troyhunt.com/how-to-build-and-how-not-to-build/ [6] Why remember me token? - java https://stackoverflow.com/questions/5314785/why-remember-me-token [7] Remember Me Feature https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/eaa200c424be45ec990e75ec8d7e8d19.html [8] Session identifiers: cookies, tokens & security best practices https://www.statsig.com/perspectives/session-identifiers-cookies-tokens-security [9] Security Tokens For Authentication https://heycoach.in/blog/security-tokens-for-authentication/