Home / Knowledge hub / Padding oracle
Knowledge hub
Padding oracle
An error message that lets an attacker decrypt data one piece at a time.
What it means
Some encryption modes, notably CBC, pad the last block of data to a fixed size. When your application decrypts a value and finds the padding wrong, it may return a different error, or take a different time, than for other failures. That difference is the oracle.
An attacker who can submit altered ciphertext and see whether the padding was accepted learns one byte at a time. With enough requests they can decrypt the whole value, and in some cases build a valid one of their own.
Why it matters
The target is usually a value you thought was sealed: an encrypted cookie, a hidden form field, a reset token, an encrypted URL parameter. If it can be decrypted, it can be read. If it can be forged, it can carry a different user id or role.
The best-known case, Vaudenay's 2002 attack, broke real products for years afterwards. The lesson holds today: any difference in how a decryption failure is handled can become an exploit path, even when nobody sees the key.
How it shows up
You meet it in apps that encrypt data themselves, in older framework versions, and in custom token or cookie schemes using AES-CBC with no integrity check. The telltale is two different outcomes for bad padding and for a bad value, such as a 500 error against a plain rejection.
The fix is to use authenticated encryption so tampered data is refused before decryption, and to return one identical error for every failure. Also check that you do not trust encrypted client-side values for anything that matters.
Questions people ask
Padding oracle, answered
Why is it called an oracle?
In cryptography an oracle is anything that answers questions about secret data. Here the application answers the question: was that padding valid?
Each answer is only a yes or no, but many of them add up to the full plaintext.
Which encryption modes are affected?
Mostly CBC with PKCS#7 padding, when decryption happens before any integrity check. Authenticated modes like GCM are not open to this attack.
Some stream ciphers have no padding, so no padding oracle.
Is a padding oracle the same as a timing attack?
Related. An oracle can be an error message or a difference in timing. Both leak through behaviour rather than output.
Uniform errors and constant-time handling close both.
Can HTTPS protect against a padding oracle?
No. HTTPS protects traffic between browser and server. The oracle sits inside your application, where the attacker is a legitimate client sending altered values.
Fix the decryption path.
How would we find one in our app?
Take an encrypted value, change a byte and resubmit. Different responses for different changes point to an oracle.
A pentest can run this against your cookies, tokens and parameters and show the decrypted result as proof.
Sources
Where this comes from
Related
Terms that sit next to this one
AES-GCM
A widely used encryption mode that also detects tampering with the data.
Timing attack
Learning a secret by measuring how long your application takes to answer.
Symmetric encryption
Encryption where the same secret key locks and unlocks the data.
Exploit
The specific sequence that turns a suspected weakness into a real one.
Session token
A random value the browser sends to show it belongs to a signed-in visit.
What does a bad value tell them?
Encrypted cookies, tokens and parameters that can be read or forged by changing bytes are exactly what we try to prove, and a finding shows the request and the recovered value. Book a pilot on one app.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.