Gateway: open config files without shell interpolation#57921
Conversation
Co-authored-by: peteryuqin <[email protected]>
Greptile SummaryThis PR correctly fixes a shell-injection vulnerability in
Confidence Score: 5/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/server-methods/config.ts
Line: 174-187
Comment:
**Unreachable `string` branch in `formatConfigOpenError`**
The `typeof error === "string"` branch is dead code in this context. `execFile`'s callback always receives an `Error`-subclass (`ExecFileException`) or `null` — it never passes a bare string. The function therefore always hits the `"message" in error` branch. Since the function is only called from one place with a value already cast to `ExecFileException`, this could simply be `err.message` (or the `object` branch alone if reuse is intended):
```suggestion
function formatConfigOpenError(error: unknown): string {
if (
typeof error === "object" &&
error &&
"message" in error &&
typeof error.message === "string"
) {
return error.message;
}
return String(error);
}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/server-methods/config.ts
Line: 573-575
Comment:
**Log path not guarded by `sanitizeLookupPathForLog`**
Elsewhere in this file (line 342) paths are passed through `sanitizeLookupPathForLog` before being embedded in log messages, which truncates them at 120 characters and strips control characters. The new `config.openFile` error log embeds the raw `configPath` without that guard. An unusually long or oddly-formed path would produce an unbounded log line:
```suggestion
context?.logGateway?.warn(
`config.openFile failed path=${sanitizeLookupPathForLog(configPath)}: ${formatConfigOpenError(err)}`,
);
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "Gateway: align config opener review fixe..." | Re-trigger Greptile |
|
Addressed the Greptile feedback on the latest head: the handler test is now platform-agnostic, and the error-path respond call again passes the explicit third undefined argument. |
|
@greptile review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 914eb03b44
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
* Gateway: open config files without shell interpolation Co-authored-by: peteryuqin <[email protected]> * Gateway: align config opener review fixes * Gateway: tidy config opener logging * Gateway: simplify config opener error path * Gateway: cover Windows config opener test path * Gateway: use literal Windows config open path --------- Co-authored-by: peteryuqin <[email protected]>
Summary
config.openFileto a no-shell launch pathChanges
src/gateway/server-methods/config.tssrc/gateway/server-methods/config.test.tsValidation
pnpm test -- src/gateway/server-methods/config.test.tspnpm buildand reached an unrelated existing TypeScript failure insrc/agents/skills/local-loader.tsNotes
powershell.exewith a quoted PowerShell string literal instead ofcmd /c startsrc/agents/skills/local-loader.tsTypeScript errors