Skip to content

Commit ca3356e

Browse files
fix(local): forward child exit code, validate content-encoding, strip control chars
- run: set process.exitCode directly instead of EXIT.GENERAL so callers can distinguish the child's error type. - server: validate content-encoding header against known values before passing to pushToSpotlightBuffer. - sanitize: strip C0 control characters (BEL, BS, etc.) in addition to ANSI escapes and newlines.
1 parent 3d60773 commit ca3356e

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/commands/local/run.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ export const runCommand = buildCommand({
157157
}
158158

159159
if (exitCode !== 0) {
160-
throw new CliError(`Process exited with code ${exitCode}`, EXIT.GENERAL);
160+
// Forward the child's exit code directly so callers (CI, scripts)
161+
// can distinguish error types. We set process.exitCode instead of
162+
// throwing CliError to avoid mapping to the CLI's semantic exit
163+
// code schema.
164+
process.exitCode = exitCode;
161165
}
162166
},
163167
});

src/commands/local/server.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ export function buildApp(
181181
) {
182182
contentType = SENTRY_CONTENT_TYPE;
183183
}
184-
const contentEncoding = c.req.header("content-encoding") as
185-
| "gzip"
186-
| "deflate"
187-
| "br"
188-
| undefined;
184+
const rawEncoding = c.req.header("content-encoding");
185+
const contentEncoding = (
186+
rawEncoding === "gzip" ||
187+
rawEncoding === "deflate" ||
188+
rawEncoding === "br"
189+
? rawEncoding
190+
: undefined
191+
) as "gzip" | "deflate" | "br" | undefined;
189192
const userAgent = c.req.header("user-agent");
190193

191194
pushToSpotlightBuffer({

src/lib/formatters/local.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import { blue, bold, cyan, green, muted, red, yellow } from "./colors.js";
44
import { stripAnsi } from "./plain-detect.js";
55

6-
/** Strip ANSI escapes and collapse newlines so envelope fields can't inject fake log lines. */
6+
/**
7+
* Strip ANSI escapes, collapse newlines, and remove C0 control characters
8+
* so envelope fields can't inject fake log lines or terminal commands.
9+
*/
710
export function sanitize(text: string): string {
8-
return stripAnsi(text).replace(/[\r\n]+/g, " ");
11+
const stripped = stripAnsi(text).replace(/[\r\n]+/g, " ");
12+
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping C0 control chars from untrusted envelope data
13+
return stripped.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
914
}
1015

1116
/** Canonical content type for Sentry envelopes. */

0 commit comments

Comments
 (0)