hasura / hasura/graphql-engine
Security: Potential RCE in Actions Codegen via untrusted template evaluation
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: Latest (Master)
CLI Version: Latest (Master)
### Environment
OSS
### What is the current behaviour?
The `actions-codegen` service in `cli-ext` uses `eval()` to execute template logic fetched from remote URLs or local file systems. Specifically, in `cli-ext/src/services/actions-codegen/template.js`, the functions `resolveCodegeneratorFromUrl` and `resolveCodegeneratorFromFs` fetch code and execute it directly.
```javascript
const resolveCodegeneratorFromUrl = async (url) => {
// ...
const codegeneratorText = await fetchResp.text();
eval(`${codegeneratorText} codegenerator = templater`);
return codegenerator;
};
```
### What is the expected behaviour?
Code execution should be performed in a secure, sandboxed environment to prevent arbitrary code execution on the user's machine. Untrusted input from external URLs should never be passed directly to `eval()`.
### How to reproduce the issue?
1. Use a Hasura CLI version that utilizes `cli-ext`.
2. Configure an action codegen traling to a malicious URL in `codegenConfig.uri`.
3. Run the codegen command.
4. The malicious code from the URL will be executed on the developer's local machine via `eval()`.
### Any possible solutions/workarounds you're aware of?
Consider replacing `eval()` with a more secure alternative:
1. Use Node.js built-in `vm` module to create a restricted sandbox for executing the template logic.
2. Implement a non-executable template format (like Mustache or Handlebars) if full JS flexibility isn't strictly required.
3. If JS is necessary, use a library like `vm2` (though it has its own history of vulnerabilities) or better, the newer `isolated-vm` for stronger isolation.
### Keywords
RCE, Security, eval, actions-codegen
Contributor guide
Research direction
Start in cli-ext/src/services/actions-codegen/template.js by reading resolveCodegeneratorFromUrl and resolveCodegeneratorFromFs, then trace how codegenConfig.uri reaches them. Reproduce with a malicious URL using the codegen command. Done means remote or local template logic is no longer executed directly with eval() and the behavior is verified in a restricted or non-executable path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100