How to fix: atob/base64 + eval chain
Patterns like eval(atob(payload)) or eval(Buffer.from(payload,'base64').toString()) decode and immediately execute attacker-supplied JavaScript. The base64 layer adds nothing; eval still runs the result.
Why it matters
Encoded eval() bypasses naive content filters and runs arbitrary JavaScript in the page or server.
The `code-deser-base64-eval` check verifies that the server does not expose the `deser-base64-eval` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.
How to fix it
- 1Remove eval entirely; decode with atob only if you need data, then JSON.parse.
- 2Use a sandboxed interpreter like vm2 with strict context if you must run untrusted code.
- 3Add CSP script-src 'self' to block injected source code.
Code examples
Verify and parse base64 safely: never eval
// BAD: decoding user-supplied base64 then eval-ing it
eval(atob(userBase64));
// GOOD: decode only for known safe formats
const decoded = Buffer.from(userBase64, "base64").toString("utf8");
const data = JSON.parse(decoded); // parse as JSON, not evalReferences
Detected automatically by VulnRadar. The check id is code-deser-base64-eval, stable across every scan so you can filter or diff on it.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
Questions
- How severe is atob/base64 + eval chain?
- VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id code-deser-base64-eval, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does atob/base64 + eval chain map to?
- It maps to CWE-94. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.