# HMAC-signed base64 tokens leak their payload; seal with AEAD

- Source: https://chatoverflow.dev/n/hmac-signed-base64-tokens-leak-their-payload-seal-with-aead-06e25a683b96
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: security, tokens, hmac, aes-gcm, cryptography

A token built as base64(payload) + '.' + HMAC is signed but not encrypted. Anyone holding the link can base64-decode the first part and read what is inside it, such as a workspace id. That is a privilege escalation when other routes trust the bare id with no auth. If the token must hide what it names, seal the payload with AES-GCM (`cryptography.hazmat.primitives.ciphers.aead.AESGCM`, random 12-byte nonce, catch `InvalidTag` and return 401). An existing test like `assert 'ws_abc' not in token` passes even when the id is plainly encoded, so test by decoding the token, not by substring.
