Critical RCE Vulnerability in AWS Amplify Studio – PoC Now Public
In May 2025, AWS disclosed a critical remote code execution (RCE) vulnerability, CVE-2025-4318, in the @aws-amplify/codegen-ui package—a core dependency for AWS Amplify Studio’s UI code generation pipeline.
The flaw, rated 9.5 on the CVSS scale, stemmed from improper input validation in the expression-binding logic that processes user-defined JavaScript expressions within UI component schemas.
How RCE Was Possible
AWS Amplify Studio enables developers to visually build UI components and export them as React code.
These components often include dynamic properties, such as labels, placeholders, or values—expressed as JavaScript snippets stored in JSON schemas.
The vulnerable versions (≤2.20.2) evaluated these expressions using unsafe techniques like eval(), new Function(), or vm.runInNewContext(), without any input sanitization or sandboxing.
Example of Unsafe Evaluation
Below is a simplified code snippet illustrating the vulnerable logic:
javascript// Vulnerable code in evaluateExpression.ts (pre-patch)
export function evaluateExpression(expression: string): any {
return eval(expression); // ⚠ UNSAFE
}
This approach allowed any string from the component schema to be executed as JavaScript, giving attackers the ability to run arbitrary code if they could inject malicious expressions into component JSON files.
Proof-of-Concept Exploit
A typical attack involved crafting a malicious component schema, such as:
json{
"componentType": "TextField",
"name": "MaliciousRCEComponent",
"properties": {
"label": { "value": "Exploitable Field" },
"placeholder": { "value": "require('child_process').execSync('touch /tmp/rce-success')" }
}
}
When the vulnerable Amplify codegen process parsed and evaluated this, it would execute the shell command on the server, demonstrating full RCE.
Attack Surface and Real-World Risks
- Exploit Prerequisites: The attacker needed authenticated access with privileges to create or modify Amplify Studio components.
- Potential Impacts:
- Arbitrary code execution on backend build systems
- Data exfiltration (e.g., AWS secrets, source code)
- Service disruption or supply chain compromise if malicious components were propagated downstream
Patch and Secure Coding
AWS patched the vulnerability in version 2.20.3 by replacing unsafe evaluation with a sandboxed, filtered approach.
The new logic uses a safeEval wrapper that:
- Blacklists dangerous keywords (e.g., require, process, child_process, eval)
- Uses the Function constructor under strict mode, with early rejection of suspicious input1
javascript// Patched code in evaluateExpression.ts (v2.20.3+)
import { safeEval } from './sandbox';
export function evaluateExpression(expression: string): any {
return safeEval(expression); // Safe wrapper
}
// sandbox.ts
export function safeEval(expr: string): any {
if (!isValidExpression(expr)) {
throw new Error("Unsafe expression detected.");
}
return Function('"use strict"; return (' + expr + ')')();
}
function isValidExpression(expr: string): boolean {
const blacklist = ['require', 'process', 'child_process', 'global', 'Function', 'eval'];
return !blacklist.some(word => expr.includes(word));
}
Mitigation and Recommendations
- Immediate Upgrade: All users must update to @aws-amplify/codegen-ui v2.20.3 or later.
- Component Audit: Review all existing component schemas for suspicious or unexpected expressions.
- Access Controls: Limit component editing rights to trusted users only.
- Forked Code: Ensure custom forks or derivatives incorporate the patch.
- Secure Coding: Avoid dynamic code evaluation in user-facing contexts; use strict input validation and static analysis tools.
This incident underscores the critical importance of input validation and sandboxing in low-code platforms, where user-supplied expressions can become high-impact attack vectors if mishandled.
AWS Amplify Studio users should act swiftly to secure their environments and adopt best practices for ongoing code safety.
To Upgrade Your Cybersecurity Skills, Take Diamond Membership With 150+ Practical Cybersecurity Courses Online – Enroll Here
Source link