Skip to main content
CriticalCodeOWASP A03:2021CWE-94

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

  1. 1Remove eval entirely; decode with atob only if you need data, then JSON.parse.
  2. 2Use a sandboxed interpreter like vm2 with strict context if you must run untrusted code.
  3. 3Add CSP script-src 'self' to block injected source code.

Code examples

Verify and parse base64 safely: never eval

TypeScript
// 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 eval

References

Detected automatically by VulnRadar. The check id is code-deser-base64-eval, stable across every scan so you can filter or diff on it.

See every code check

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.

Propose a checkHow a check is built

Scan your own site for atob/base64 + eval chain

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: atob/base64 + eval chain | VulnRadar