Skip to content

Commit ea7548f

Browse files
anandgupta42claude
andcommitted
fix: pin prototype-pollution test to a real malicious payload
CodeRabbit caught that the __proto__ regression guard was hollow: JSON.stringify({__proto__: ...}) produces `{}` — `__proto__` in object-literal syntax is the prototype setter, not an enumerable own property, so it never makes it into the JSON. The test was serializing an empty payload and asserting prototype wasn't polluted (trivially true). Replace the JSON.stringify call with a hand-written JSON literal containing an explicit "__proto__" key. parseAPICallError's JSON.parse now actually receives the malicious key, exercising the regression guard against a future refactor that switches to Object.assign / spread. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 724b114 commit ea7548f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎packages/opencode/test/skill/release-v0.7.1-adversarial.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@ describe("parseAPICallError — JSON-scalar and non-object bodies", () => {
110110

111111
describe("parseAPICallError — prototype pollution attempts", () => {
112112
test("__proto__ in body does not pollute Object.prototype", () => {
113+
// Important: write the JSON as a literal string. `JSON.stringify({__proto__: ...})`
114+
// produces `{}` because in object-literal syntax `__proto__` is the prototype
115+
// setter (it sets [[Prototype]]) rather than an own enumerable property, and
116+
// JSON.stringify only walks own enumerables. Building the JSON by hand puts
117+
// the malicious key on the wire so JSON.parse in parseAPICallError actually
118+
// sees it — which is the surface a hostile gateway would exploit.
113119
const before = (Object.prototype as any).polluted
114120
ProviderError.parseAPICallError({
115121
providerID: "openai" as any,
116122
error: makeAPICallError({
117123
message: "Bad Request",
118124
statusCode: 400,
119-
responseBody: JSON.stringify({
120-
__proto__: { polluted: "yes" },
121-
error: { message: "harmless surface" },
122-
}),
125+
responseBody: '{"__proto__":{"polluted":"yes"},"error":{"message":"harmless surface"}}',
123126
}),
124127
})
125128
expect((Object.prototype as any).polluted).toBe(before)

0 commit comments

Comments
 (0)