Skip to main content
Menu
Advisories

UnusedVariable compiles the flow variable name into a RegExp unescaped

GHSA-FPVW-W7FF-H7VRPublished Updated GitHub

Description

UnusedVariable compiles the flow variable name into a RegExp unescaped

new RegExp(variableName, "gi") is built from a name read straight out of the scanned .flow-meta.xml, so a crafted variable name is a regex pattern, and a pathological one stalls the scanner.

Details

Where it is

packages/core/src/main/rules/UnusedVariable.ts:

const variableName = variable.name;

const nodeMatches = [
  ...JSON.stringify(flow.elements.filter((node) => node instanceof core.FlowNode)).matchAll(
    new RegExp(variableName, "gi")
  ),
].map((a) => a.index);

check() does this four times in the same loop body: against the FlowNode elements, the FlowResource elements, JSON.stringify(variable) itself, and the FlowVariable elements. Every one of them compiles variableName (or variable.name) directly. No escaping anywhere between the XML and the constructor.

The value's origin is packages/core/src/main/models/Flow.ts, which builds FlowVariable instances from the parsed XML nodes through a shared helper:

} else if (Flow.VARIABLE_TAGS.includes(nodeType as any)) {
  this.processNodeType(data, nodeType, allNodes, FlowVariable);

and in processNodeType:

allNodes.push(new NodeClass(node.name, nodeType, node));

node.name is whatever the file says. The rule is on by default: packages/core/src/main/config/RuleRegistry.ts does registry.register("unused-variable", UnusedVariable, "UnusedVariable"), GetRuleDefinitions.ts selects all non-disabled rules in merged mode, and ScanFlows.ts calls rule.execute(...) for each selected rule.

Confirmed on main at HEAD eeeb0638f14eaf587202725f510dd6343821ebd7 and on the shipped action tag action-v3.7.2.

Impact

Severity

MEDIUM. CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H.

AV:L and PR:L because the attacker acts by contributing a file that the victim's job scans, which means having write access to a branch or an accepted PR, not reaching a network service. AC:L because the pattern is a handful of characters. UI:N because the scan runs as a job step without anyone clicking. C:N/I:N because nothing is read or altered. A:H for the scanning process, bounded in practice by the CI job timeout.

What an attacker gets

The realistic setting is CI: the scanner runs as a gate on pull requests, and a PR author controls the .flow-meta.xml files it scans. They name a flow variable something like (a+)+$, and the scan job burns CPU until the runner's job timeout kills it.

That is a denial of the scanner, so in a repository where the scan is a required check, it is a way to stall the pipeline rather than to alter a result. What it is not: no code executes, nothing is disclosed, and the scanner's findings for other files are unaffected up to the point it hangs.

Because the pattern is fully attacker-chosen, the regex-injection framing is broader than just backtracking (the name could also be crafted to match or not match arbitrarily, distorting the unused-variable result), but the availability effect is the one I have measured.

How I checked

Partial, and here is the split.

I did not run sf flow scan against a crafted flow file, so I do not have a scanner run that hangs. What I ran is the exact construction the rule performs, new RegExp(pattern, "gi") followed by .matchAll() on a non-matching subject, to establish the cost:

node -e "const variableName='(a+)+$'; const target='a'.repeat(30)+'b'; const re=new RegExp(variableName,'gi'); const t=Date.now(); let cnt=0; for (const m of target.matchAll(re)) {cnt++;} console.log(JSON.stringify({cnt,ms:Date.now()-t}));"

Observed output, verbatim, Node.js v22:

{"cnt":0,"ms":16106}

Sixteen seconds on a 31-character subject, with zero matches. V8's regex engine has no backtracking limit, so lengthening the subject grows this without bound, and the subject in the rule is JSON.stringify(flow.elements.filter(...)), which is the whole serialised flow rather than 31 characters.

The link from that to the scanner is a code reading:

grep -n "new RegExp" packages/core/src/main/rules/UnusedVariable.ts
grep -n "escapeRegExp\|replace(/\[" packages/core/src/main/rules/UnusedVariable.ts
grep -n "processNodeType" packages/core/src/main/models/Flow.ts

The first returns four hits, the second returns nothing, and that second result is the point.

A claim I withdrew

An earlier version of this report also argued that malformed XML is a scan-evasion vector: ParseFlows.ts catches parse exceptions into ParsedFlow.errorMessage, ScanFlows.ts filters those entries out before rules run, and the CLI reports only ScanResult[], so a file that fails to parse produces no findings. The code reading is correct, but I never executed it, and "the scanner reports nothing for a file it could not parse" may well be intended behaviour with the error surfaced elsewhere in the output. I am not going to file an unexecuted behavioural claim next to a measured one, so I have dropped it. If it is of interest as a hardening item I am happy to raise it separately as an issue rather than as a security report.

Suggested fix

Escape the name before compiling it:

function escapeRegExp(s: string): string {
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

const re = new RegExp(escapeRegExp(variableName), "gi");

Since the rule's semantics are "does the serialised flow contain this variable name", a literal includes() or a count over split() would be simpler still and removes the regex engine from the path entirely. Either way, the same pattern is worth grepping for across the other rules in packages/core/src/main/rules/.

Not a duplicate of CVE-2025-67750

CVE-2025-67750 is the advisory I audited from for this project. It did not touch UnusedVariable.ts: the unescaped new RegExp(variableName, "gi") is present unchanged on main and on action-v3.7.2, and no escaping helper exists anywhere in that package.

AI assistance

I used an AI assistant for the audit and for drafting this report. I ran the backtracking measurement above myself and captured the output, and I read UnusedVariable.ts, Flow.ts, RuleRegistry.ts and ScanFlows.ts by hand to confirm the name reaches the constructor unescaped and that the rule is enabled by default.

Affected versions

References

GitHub · Flow-Scanner/lightning-flow-scanner