Repository navigation
fix(codex): sanitize approval preview text - #70569
Conversation
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟠 Approval decision context uses truncated/sanitized command/reason previews, enabling policy/approval bypass
Description
Security impact:
Vulnerable code: const commandPreview = sanitizeApprovalPreview(readDisplayCommandPreview(params.requestParams), 180);
const reasonPreview = sanitizeApprovalPreview(readStringPreview(params.requestParams, "reason"), 180);
const command = commandPreview.text;
const reason = reasonPreview.text;
...
eventDetails: {
...(command ? { command } : {}),
...(reason ? { reason } : {}),
}While RecommendationEnsure approval/policy decisions are based on the full underlying command/reason, while still protecting the UI from terminal escape injection. Suggested approach:
Example: const commandFull = readDisplayCommand(params.requestParams); // full
const commandPreview = sanitizeApprovalPreview(previewSource(commandFull ?? ""), 180);
await requestPluginApproval({
...,
description: `Command: ${formatApprovalPreviewSubject(commandPreview.text ?? "", commandPreview.omitted)}`,
// add non-truncated structured context for policy engines:
context: { commandFull, reasonFull },
});
emitApprovalEvent(paramsForRun, {
...,
commandPreview: commandPreview.text,
commandPreviewOmitted: commandPreview.omitted,
// do NOT overwrite `command` with the preview if consumers treat it as authoritative
});Also update approval consumers to treat 2. 🟡 Approval preview sanitization does not flag omitted/modified content unless clipped or empty
Description
This creates a deception risk in approval UX:
An attacker could craft a command/reason containing hidden or terminal-control content that is stripped for display, causing the approver to see a different (sanitized) string without any indication that sanitization occurred. Vulnerable code: const rawPreview = source.value.replace(DANGLING_TERMINAL_SEQUENCE_SUFFIX_RE, "");
const sanitized = sanitizeVisibleScalar(rawPreview);
...
return { text: truncate(sanitized, maxLength), omitted: source.clipped };RecommendationTreat sanitization changes as omission as well (not only clipping), so approvers are warned whenever unsafe/control content was removed. For example: function sanitizeApprovalPreview(
source: ApprovalPreviewSource | undefined,
maxLength: number,
): SanitizedApprovalPreview {
if (!source || !source.value) return { omitted: false };
const rawPreview = source.value.replace(DANGLING_TERMINAL_SEQUENCE_SUFFIX_RE, "");
const sanitized = sanitizeVisibleScalar(rawPreview);
// Flag omission if we clipped OR if sanitization altered the string.
const sanitizedChanged = sanitized !== sanitizeVisibleScalar(source.value);
const omitted = source.clipped || rawPreview !== source.value || sanitizedChanged;
if (!sanitized) return { omitted: true };
return { text: truncate(sanitized, maxLength), omitted };
}Alternatively, explicitly detect matches of the stripping regexes (e.g., This ensures 3. 🟡 Approval prompt can omit command/reason for exec approvals, enabling misleading approvals
DescriptionThe approval bridge can generate an approval request without any command or reason shown to the approver, yet still return an "accept" decision for
This creates a confused-deputy / social-engineering risk: a malicious or compromised caller that can influence Vulnerable code (preview becomes for (const part of command) {
if (typeof part !== "string") {
return undefined;
}
}
...
: `Request method: ${params.method}`RecommendationFail closed for exec approvals when no trustworthy preview can be produced. Suggested change:
Example: if (params.method === "item/commandExecution/requestApproval") {
const source = readDisplayCommandPreview(params.requestParams);
const preview = sanitizeApprovalPreview(source, 180);
if (!preview.text) {
// no command displayed -> deny
return {
kind,
title,
description: "Command preview unavailable; denying approval request.",
// ...
forceDeny: true,
};
}
}And when building the response, if Analyzed PR: #70569 at commit Last updated on: 2026-04-24T04:19:39Z |
Greptile SummaryThis PR adds Confidence Score: 5/5Safe to merge; the sanitization logic is correct, well-tested, and scoped only to command/reason preview formatting. No P0 or P1 findings. The ANSI and control-character regex construction via String.raw + RegExp is correct, ordering of replacements is sound, truncation is properly folded into the helper, and the new tests confirm expected output for both code paths. Only a trivial style nit remains. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/codex/src/app-server/approval-bridge.ts
Line: 20-21
Comment:
**Missing blank line before export**
There is no blank line separating the new module-level constant declarations from the exported function, which is inconsistent with the surrounding style and makes the module header harder to scan at a glance.
```suggestion
const CONTROL_CHARACTER_RE = new RegExp(String.raw`[\u0000-\u001f\u007f]+`, "g");
export async function handleCodexAppServerApprovalRequest(params: {
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(codex): sanitize approval preview te..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b047548936
ℹ️ 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".
|
Codex maintainer deep review: useful fix, but I would not merge this yet because approval preview text is a security/UI boundary. Please harden before landing:
The scope is otherwise good: sanitizing only the command/reason preview fields and leaving permission approval details alone is the right boundary. |
|
@steipete pushed a hardening follow-up in Covered all four items from your review:
Scope stays the same: only Local verification:
|
Co-authored-by: Lucenx9 <[email protected]>
Co-authored-by: Lucenx9 <[email protected]>
|
Codex review follow-up: landed as Rewritten to cap and sanitize approval preview text before command-array joins, strip terminal/control/invisible formatting controls, and mark omitted/truncated previews explicitly. Focused local proof before push: |
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Harden Codex app-server approval preview text sanitization and truncation handling. Thanks @Lucenx9. Co-authored-by: Lucenx9 <[email protected]>
Summary
commandandreasontext nearly raw intoplugin.approval.requestdescriptions and approval events.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
command/reasonfields as display-ready strings and reused them directly in human-facing approval payloads.Regression Test Plan (if applicable)
extensions/codex/src/app-server/approval-bridge.test.tsUser-visible / Behavior Changes
Diagram (if applicable)
Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation:Repro + Verification
Environment
Steps
handleCodexAppServerApprovalRequestwith a command approval containing newlines / ANSI escapes inrequestParams.command.handleCodexAppServerApprovalRequestwith a file approval containing newlines / ANSI escapes inrequestParams.reason.plugin.approval.requestpayload and emitted approval events.Expected
Actual
Evidence
Human Verification (required)
Review Conversations
Compatibility / Migration
Yes)No)No)Risks and Mitigations