𝗖𝗕𝗖 𝗕𝗶𝘁 𝗙𝗹𝗶𝗽𝗽𝗶𝗻𝗴 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
Encryption does not mean your data is safe from tampering.
Many developers make this mistake. They think if an attacker cannot read the data, they cannot change it. This is wrong. Cryptography treats secrecy and integrity as two different tasks.
The CBC Bit Flipping attack proves this. An attacker can change your data without knowing your secret key.
Here is how it works:
AES does not encrypt data in one large piece. It breaks data into 16-byte blocks. In CBC mode, these blocks chain together. The encrypted output of the first block mixes into the plaintext of the second block.
This chain creates a weakness during decryption. To get the original text of Block 2, the server decrypts it and combines it with the ciphertext from Block 1.
An attacker can exploit this:
- The attacker intercepts your encrypted traffic.
- They do not know the key, so the data looks like gibberish.
- They change specific bits in the ciphertext of Block 1.
- They send this altered data to your server.
- When the server decrypts it, the change in Block 1 shifts the math for Block 2.
The attacker does not need to read the message. They just flip bits to change the final result.
Consider an old web app using encrypted cookies for sessions. A cookie might hold: userid=994;role=user;
An attacker intercepts this cookie and flips bits in the ciphertext. They send many requests until the server accepts one. Because the server only checks if the data decrypts, it processes the modified text. Suddenly, the decrypted string reads: userid=994;role=admi;
The attacker now has admin access. They never read the key or the original cookie.
The mistake is assuming encryption guarantees integrity.
- Confidentiality stops people from reading data.
- Integrity stops people from changing data.
To fix this, use Authenticated Encryption like AES-GCM. It creates a cryptographic tag. This tag acts like a seal. If an attacker changes even one bit, the seal breaks. The server rejects the data immediately.
If you must use CBC, use an Encrypt-then-MAC architecture. Create an authentication code for the ciphertext and verify it before you start decryption.
Secret data is not always trustworthy data. Always prove your data is unchanged before you use it to make decisions.