Skip to content
Myr

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

2 files+56 added−0 removed

modified:src/utils/body.test.ts+52 added
158 unmodified lines
159 a: { b: { c: { d: 'value' } } },160 })161 })162163 it('should skip keys starting with __proto__. to prevent prototype pollution', async () => {164 const data = new FormData()165 data.append('__proto__.polluted', 'malicious')166167 const req = createRequest(FORM_URL, 'POST', data)168169 expect(await parseBody(req, { dot: true })).toEqual({})170 })171172 it('should skip keys containing nested __proto__. to prevent prototype pollution', async () => {173 const data = new FormData()174 data.append('a.__proto__.polluted', 'malicious')175176 const req = createRequest(FORM_URL, 'POST', data)177178 expect(await parseBody(req, { dot: true })).toEqual({})179 })180181 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')185186 const req = createRequest(FORM_URL, 'POST', data)187188 await parseBody(req, { dot: true })189190 expect(({} as Record<string, unknown>).injected).toBeUndefined()191 })192193 it('should parse key ending with __proto__ as a normal value', async () => {194 const data = new FormData()195 data.append('a.__proto__', 'value')196197 const req = createRequest(FORM_URL, 'POST', data)198199 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 })203204 it('should parse key containing __proto__ as a substring normally', async () => {205 const data = new FormData()206 data.append('data__proto__key.value', 'test')207208 const req = createRequest(FORM_URL, 'POST', data)209210 expect(await parseBody(req, { dot: true })).toEqual({211 data__proto__key: { value: 'test' },212 })213 })214215 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 lines
modified:src/utils/body.ts+4 added
206 unmodified lines
207 form: BodyData,208 key: string,209 value: BodyDataValue<Partial<ParseBodyOptions>>210): void => {211 if (/(?:^|\.)__proto__\./.test(key)) {212 return213 }214215 let nestedForm = form216 const keys = key.split('.')217218 keys.forEach((key, index) => {
15 unmodified lines