Turn off compression on API responses that carry a secret
-
What you'll see
Nothing. The endpoint works, and the browser's network tab shows
content-encoding: bron the response - which is what you want for nearly every endpoint. Nothing tells you that one of them returns a value a third party should not be able to work out. -
What's actually happening
Compression removes repetition. When a guess the attacker placed in the request matches part of the secret in the same response, the two compress together and the response gets shorter:
The caller sent ?label=The body contains Compressed size key=sk_7Q"label":"key=sk_7Q" ... "key":"sk_7Qm4..."shorter - the guess matches key=sk_7X"label":"key=sk_7X" ... "key":"sk_7Qm4..."one byte longer Someone who can make the visitor's browser send many such requests, and can see the size of the encrypted responses on the network, guesses the secret one character at a time. HTTPS does not hide the length. The attack is slow and needs both conditions in one response - which is why only those responses need the header.
Only the body is compressed, never the headers. The session cookie
writeJwtsets is a header, so it is not affected. -
What to do
Set the header in the endpoint that returns the secret
setHeaderreplaces theCache-ControlDocly sets, so includeno-storetoo - a secret should not be cached either.// #/API/createKey.js - returns a new API key and echoes the label the caller sent export default (label) => { docly.setHeader("Cache-Control", "no-store, no-transform"); return { label: label, key: createKey(label) }; };Which responses need it
The response body contains Set no-transform? A secret and something the caller sent (query, form, a header) Yes A secret, and nothing from the request Not needed - harmless if set Neither - lists, pages, search results No, keep the compression What Docly does for you
Docly's own sign-in and token endpoints are never compressed, and the cookie from
writeJwtis a header, which is never compressed. What your own endpoints write in the body is up to the endpoint.
Last reviewed 19 Nov 2026