Skip to content

Commit 32bf331

Browse files
authored
test(openapi): bracket notion prototype pollution (#1455)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added test coverage for prototype pollution safety, validating that the serializer properly handles and prevents related attack vectors. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ba7984f commit 32bf331

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

packages/openapi-client/src/adapters/standard/bracket-notation.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,32 @@ describe('standardBracketNotationSerializer', () => {
275275
})(),
276276
})
277277
})
278+
279+
it('safety against prototype pollution', () => {
280+
const result = serializer.deserialize([
281+
['__proto__[polluted]', '1'],
282+
['constructor[polluted]', '2'],
283+
['nested[__proto__][polluted]', '3'],
284+
['nested[constructor][polluted]', '4'],
285+
]) as any
286+
287+
// eslint-disable-next-line no-proto, no-restricted-properties
288+
expect(result.__proto__).toEqual({ polluted: '1' })
289+
expect(result.constructor).toEqual({ polluted: '2' })
290+
// eslint-disable-next-line no-proto, no-restricted-properties
291+
expect(result.nested.__proto__).toEqual({ polluted: '3' })
292+
expect(result.nested.constructor).toEqual({ polluted: '4' })
293+
294+
// if `.polluted` is not handled correctly, access may fall back to `.__proto__.polluted` and cause pollution
295+
expect(result.polluted).toBeUndefined()
296+
expect(result.nested.polluted).toBeUndefined()
297+
298+
// does not affect the global object prototype
299+
// eslint-disable-next-line no-proto, no-restricted-properties
300+
expect(({} as any).__proto__.polluted).toBeUndefined()
301+
expect(({} as any).constructor.polluted).toBeUndefined()
302+
expect(({} as any).polluted).toBeUndefined()
303+
})
278304
})
279305

280306
it.each([

0 commit comments

Comments
 (0)