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(plugin): read Git commit subjects as UTF-8 (#593)

ianw-oai27f70f3e28a9
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_target.py b/sdk/typescript/_bundled_plugin/scripts/workbench_target.py
index 05faf6e03..fdbce930d 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_target.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_target.py
@@ -135,7 +135,15 @@ def git_command(
environment.pop(name, None)
environment["GIT_LITERAL_PATHSPECS"] = "1"
# Repository-local config is untrusted; fsmonitor may name an executable hook.
- command = ["git", "-c", "core.fsmonitor=false", "-C", str(target)]
+ command = [
+ "git",
+ "-c",
+ "core.fsmonitor=false",
+ "-c",
+ "i18n.logOutputEncoding=UTF-8",
+ "-C",
+ str(target),
+ ]
if git_dir is not None and work_tree is not None:
command.extend(["--git-dir", str(git_dir), "--work-tree", str(work_tree)])
full_command = [*command, *args]
@@ -548,9 +556,10 @@ def git_target_metadata(target: Path) -> dict[str, Any]:
branch = git_output(target, "symbolic-ref", "--quiet", "--short", "HEAD")
metadata.update({"branch": branch, "detachedHead": revision is not None and branch is None})
if revision is not None:
+ subject = git_bytes(target, "show", "-s", "--format=%s", "HEAD")
metadata.update(
{
- "commitSubject": git_output(target, "show", "-s", "--format=%s", "HEAD"),
+ "commitSubject": (subject or b"").decode("utf-8").strip() or None,
"revision": revision,
"shortRevision": revision[:7],
}
diff --git a/sdk/typescript/tests-ts/workbench-canonical-paths.test.ts b/sdk/typescript/tests-ts/workbench-canonical-paths.test.ts
index dd04b8236..67dbddeab 100644
--- a/sdk/typescript/tests-ts/workbench-canonical-paths.test.ts
+++ b/sdk/typescript/tests-ts/workbench-canonical-paths.test.ts
@@ -129,6 +129,34 @@ function runPythonProbe(
}
describe("bundled workbench canonical paths", () => {
+ test("reads Unicode commit subjects regardless of locale or Git log encoding", async () => {
+ const repository = await temporaryDirectory();
+ expect(
+ runPythonProbe(
+ [
+ "import json, subprocess, sys",
+ "from pathlib import Path",
+ "sys.path.insert(0, sys.argv[1])",
+ "import workbench_target as target",
+ "repository = Path(sys.argv[2])",
+ "def git(*args):",
+ " subprocess.run(['git', '-C', str(repository), *args], check=True, capture_output=True)",
+ "git('init', '-q')",
+ "subjects = [('UTF-8', 'docs: \\u65e5\\u672c\\u8a9e \\ud55c\\uad6d\\uc5b4 \\U0001f527'), ('ISO-8859-1', 'docs: caf\\u00e9')]",
+ "for log_encoding, subject in subjects:",
+ " git('-c', 'user.name=Test', '-c', '[email protected]', '-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-qm', subject)",
+ " git('config', 'i18n.logOutputEncoding', log_encoding)",
+ " for encoding in ('cp932', 'cp949'):",
+ " subprocess._text_encoding = lambda: encoding",
+ " assert target.git_target_metadata(repository)['commitSubject'] == subject",
+ " assert target.git_bytes(repository, 'show', '-s', '--format=%s', 'HEAD') == (subject + '\\n').encode('utf-8')",
+ "print(json.dumps({'subjects': len(subjects), 'locales': 2}))",
+ ].join("\n"),
+ repository,
+ ),
+ ).toEqual({ subjects: 2, locales: 2 });
+ });
+
testPosix(
"rejects private scan directories under insecure shared parents",
async () => {