Commit 1773c93
Harden prompt boundary against hostile PR body / prior-review content
The reverted Codex workflow already wraps prior-review content in
<previous-ai-review-output untrusted="true"> and tells the reviewer not to
follow instructions from it, but it didn't sanitize the closing tag — a
hostile PR body containing literal "</pr-body>" or a prior comment
echoing "</previous-ai-review-output>" could close the wrapper early
and steer subsequent text as trusted instructions.
This re-applies the closing-tag sanitization that PR #415 introduced,
without bringing back the broader CI changes that #416 reverts:
CI workflow (.github/workflows/ai_pr_review.yml):
- Wrap PR_BODY in <pr-body untrusted="true">...</pr-body>
- Inline python3 sanitizer escapes </pr-body> and
</previous-ai-review-output> (case- and whitespace-tolerant) to
HTML entities before interpolation
Local script (.claude/scripts/openai_review.py):
- Add _sanitize_previous_review() helper (mirrors the workflow's regex)
- Wrap previous_review with untrusted="true" attribute and run it
through the sanitizer in compile_prompt()
Tests (tests/test_openai_review.py):
- TestSanitizePreviousReview: case/whitespace variants + clean-content
pass-through + compile_prompt regressions for wrapper attribute
and hostile-content sanitization
- TestWorkflowPromptHardening: workflow YAML must contain the
<pr-body untrusted="true"> wrapper and the HTML-entity escapes for
both closing-tag patterns
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 9c59f66 commit 1773c93
3 files changed
Lines changed: 135 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
954 | 954 | | |
955 | 955 | | |
956 | 956 | | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
957 | 972 | | |
958 | 973 | | |
959 | 974 | | |
| |||
1021 | 1036 | | |
1022 | 1037 | | |
1023 | 1038 | | |
1024 | | - | |
1025 | | - | |
| 1039 | + | |
| 1040 | + | |
1026 | 1041 | | |
1027 | 1042 | | |
1028 | 1043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
125 | 154 | | |
126 | 155 | | |
127 | 156 | | |
128 | 157 | | |
129 | 158 | | |
130 | 159 | | |
131 | 160 | | |
| 161 | + | |
132 | 162 | | |
| 163 | + | |
133 | 164 | | |
134 | 165 | | |
135 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
1590 | 1590 | | |
1591 | 1591 | | |
1592 | 1592 | | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
1593 | 1678 | | |
1594 | 1679 | | |
1595 | 1680 | | |
| |||
0 commit comments