OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(plugin): recognize PHP heredoc terminators inside expressions (#1236)
1286275c46833b
diff --git a/plugins/codex-security/scripts/rank_preview.py b/plugins/codex-security/scripts/rank_preview.pyindex 95e54e4b6..2988d3125 100644--- a/plugins/codex-security/scripts/rank_preview.py+++ b/plugins/codex-security/scripts/rank_preview.py@@ -303,13 +303,13 @@ def mask_c_style_source(text: str, suffix: str) -> str:continueif heredoc_terminator:if index == 0 or text[index - 1] == "\n":- line_end = text.find("\n", index)- if line_end < 0:- line_end = len(text)- candidate = text[index:line_end].strip().removesuffix(";")- if candidate == heredoc_terminator:- masked.extend(" " * (line_end - index))- index = line_end+ # PHP identifiers allow every non-ASCII byte, including non-word characters.+ terminator_match = re.compile(+ rf"[ \t]*{heredoc_terminator}(?![A-Za-z0-9_\x80-\U0010ffff])"+ ).match(text, index)+ if terminator_match:+ masked.extend(" " * (terminator_match.end() - index))+ index = terminator_match.end()heredoc_terminator = ""continuemasked.append(" ")diff --git a/plugins/codex-security/tests/test_rank_preview.py b/plugins/codex-security/tests/test_rank_preview.pyindex 8070f14fa..70557f4f4 100644--- a/plugins/codex-security/tests/test_rank_preview.py+++ b/plugins/codex-security/tests/test_rank_preview.py@@ -551,6 +551,63 @@ def test_javascript_preview_lists_class_field_arrow_handlers(tmp_path: Path) ->assert "method Controller.validate" in preview[email protected]("opener", ["TXT", '"TXT"', "'TXT'"])[email protected]("indent", ["", " "])+def test_php_heredoc_terminator_can_continue_expression(+ tmp_path: Path, opener: str, indent: str+) -> None:+ source = f"""<?php+function before() {{}}++$values = [<<<{opener}+{indent}hello+{indent}TXT,+];++function after() {{}}+"""++ preview = generate_preview(tmp_path, "sample.php", source)++ assert "function before" in preview+ assert "function after" in preview++[email protected]("opener", ["TXT", '"TXT"', "'TXT'"])+def test_php_heredoc_terminator_preserves_following_brace(tmp_path: Path, opener: str) -> None:+ source = f"""<?php+class Service {{+ public function template() {{+ return <<<{opener}+hello+TXT; }}+ public function visible() {{}}+}}+"""++ preview = generate_preview(tmp_path, "Service.php", source)++ assert "method Service.template" in preview+ assert "method Service.visible" in preview++[email protected]("opener", ["TXT", "'TXT'"])[email protected]("suffix", ["_more", "2", "😀", "\u0301"])+def test_php_heredoc_label_prefix_stays_in_body(tmp_path: Path, opener: str, suffix: str) -> None:+ source = f"""<?php+function before() {{}}+$value = <<<{opener}+TXT{suffix} {{+TXT;+function after() {{}}+"""++ preview = generate_preview(tmp_path, "sample.php", source)++ assert "function before" in preview+ assert "function after" in preview++def test_php_heredoc_does_not_hide_following_method(tmp_path: Path) -> None:source = """<?phpclass Service {