Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(action): do not split surrogate pairs in truncated report text (#2133)

wjaf94f47318d8
diff --git a/github-action/dist/index.cjs b/github-action/dist/index.cjs
index 8b0619e6a..aae63d0f9 100644
--- a/github-action/dist/index.cjs
+++ b/github-action/dist/index.cjs
@@ -99399,7 +99399,9 @@ async function uploadReports(reports, inputs, tempRoot) {
// src/reporting.ts
function plain(value, limit) {
const text = value.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, "");
- return text.slice(0, limit);
+ const prefix2 = text.slice(0, limit);
+ const codePoint = text.codePointAt(prefix2.length - 1);
+ return codePoint !== void 0 && codePoint > 65535 ? prefix2.slice(0, -1) : prefix2;
}
function html(value) {
return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/@/g, "&#64;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/[\\`*_\[\]~]/g, (character) => `&#${character.charCodeAt(0)};`);
diff --git a/github-action/src/reporting.ts b/github-action/src/reporting.ts
index 045e81694..64bdddd18 100644
--- a/github-action/src/reporting.ts
+++ b/github-action/src/reporting.ts
@@ -5,7 +5,10 @@ import type { ScanResults } from './results.js';
export function plain(value: string, limit?: number): string {
const text = value.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '');
- return text.slice(0, limit);
+ const prefix = text.slice(0, limit);
+ // A two-unit code point starting at the last included unit spans the cut.
+ const codePoint = text.codePointAt(prefix.length - 1);
+ return codePoint !== undefined && codePoint > 0xffff ? prefix.slice(0, -1) : prefix;
}
function html(value: string): string {
// Inline HTML still parses Markdown; entities keep report fields literal.
diff --git a/github-action/tests/reporting.test.ts b/github-action/tests/reporting.test.ts
index efd87269a..65dd06f8b 100644
--- a/github-action/tests/reporting.test.ts
+++ b/github-action/tests/reporting.test.ts
@@ -10,6 +10,16 @@ test('credential-shaped text and encodings remain in diagnostics',()=>{
assert.equal(plain(text),text);
}
});
+test('truncation drops only the first half of a split surrogate pair', () => {
+ const prefix = 'a'.repeat(199);
+ assert.equal(plain(prefix + 'πŸ˜€', 200), prefix);
+ assert.equal(plain(prefix + 'πŸ˜€', 201), prefix + 'πŸ˜€');
+
+ const unpaired = prefix + '\uD83D';
+ assert.equal(plain(unpaired), unpaired);
+ assert.equal(plain(unpaired, 200), unpaired);
+ assert.equal(plain(unpaired + 'x', 200), unpaired);
+});
test('finding titles and messages cannot become Markdown links, images or raw HTML',()=>{
const result = {scanStatus:'completed',policyStatus:'passed',reportStatus:'ready',counts:{critical:0,high:1,medium:0,low:0,informational:0},errors:[],
findings:[{severity:'high',title:'![click](https://example.invalid) <img src=x> @someone',summary:'</pre><script>bad</script>',path:'src/app.ts',startLine:1}]} as unknown as ScanResults;