Merge commit from fork
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Taku Amano · committed by GitHub · parent 3f88636 · Browse files · 2 files·+56 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+56 added−0 removed
- tests:+52 added−0 removed
- other:+4 added−0 removed
Provenance
- Commit
ef90225- Tree
a113fa2- Author
Taku Amano <taku@taaas.jp>- Committer
GitHub <noreply@github.com>- Parent
3f88636
2 files changed+56 added−0 removed
modified:src/utils/body.test.ts+52 added
158 unmodified lines159 a: { b: { c: { d: 'value' } } },160 })161 })162 163+ it('should skip keys starting with __proto__. to prevent prototype pollution', async () => {164+ const data = new FormData()165+ data.append('__proto__.polluted', 'malicious')166+167+ const req = createRequest(FORM_URL, 'POST', data)168+169+ expect(await parseBody(req, { dot: true })).toEqual({})170+ })171+172+ it('should skip keys containing nested __proto__. to prevent prototype pollution', async () => {173+ const data = new FormData()174+ data.append('a.__proto__.polluted', 'malicious')175+176+ const req = createRequest(FORM_URL, 'POST', data)177+178+ expect(await parseBody(req, { dot: true })).toEqual({})179+ })180+181+ it('should not pollute Object.prototype via __proto__ keys', async () => {182+ const data = new FormData()183+ data.append('__proto__.injected', 'yes')184+ data.append('a.__proto__.injected', 'yes')185+186+ const req = createRequest(FORM_URL, 'POST', data)187+188+ await parseBody(req, { dot: true })189+190+ expect(({} as Record<string, unknown>).injected).toBeUndefined()191+ })192+193+ it('should parse key ending with __proto__ as a normal value', async () => {194+ const data = new FormData()195+ data.append('a.__proto__', 'value')196+197+ const req = createRequest(FORM_URL, 'POST', data)198+199+ const result = await parseBody(req, { dot: true })200+ expect(result).toHaveProperty('a')201+ expect(Object.getOwnPropertyDescriptor((result as Record<string, Record<string, string>>).a, '__proto__')?.value).toBe('value')202+ })203+204+ it('should parse key containing __proto__ as a substring normally', async () => {205+ const data = new FormData()206+ data.append('data__proto__key.value', 'test')207+208+ const req = createRequest(FORM_URL, 'POST', data)209+210+ expect(await parseBody(req, { dot: true })).toEqual({211+ data__proto__key: { value: 'test' },212+ })213+ })214+215 it('should parse nested values if `dot` option is true', async () => {216 const data = new FormData()217 data.append('obj.key1', 'value1')218 data.append('obj.key2', 'value2')206 unmodified linesmodified:src/utils/body.ts+4 added
206 unmodified lines207 form: BodyData,208 key: string,209 value: BodyDataValue<Partial<ParseBodyOptions>>210 ): void => {211+ if (/(?:^|\.)__proto__\./.test(key)) {212+ return213+ }214+215 let nestedForm = form216 const keys = key.split('.')217 218 keys.forEach((key, index) => {15 unmodified lines