]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: do not allow invalid hazardous keys in query (#880)
authorAlex Kozack <cawa-93@users.noreply.github.com>
Mon, 26 Apr 2021 15:26:46 +0000 (18:26 +0300)
committerGitHub <noreply@github.com>
Mon, 26 Apr 2021 15:26:46 +0000 (17:26 +0200)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
__tests__/parseQuery.spec.ts
src/query.ts

index b16c86245e3309843669915f19a28dd6aea649ce..7c849bbdf1b9d56a9355596da9938d2ad9123d33 100644 (file)
@@ -85,4 +85,15 @@ describe('parseQuery', () => {
 
     expect('decoding "%"').toHaveBeenWarnedTimes(1)
   })
+
+  it('ignores __proto__', () => {
+    const query = parseQuery('__proto__=1')
+    expect(query.__proto__).toEqual(Object.prototype)
+    expect(query.constructor).toEqual(Object)
+  })
+
+  it('ignores build-in methods', () => {
+    const query = parseQuery('toString=1')
+    expect(query.toString).toEqual(Object.prototype.toString)
+  })
 })
index f13c170454f81ceca5288f1b91d88e7bdbcda69c..c936c7a2704e01d7418327a92cf7f5a303428c2e 100644 (file)
@@ -55,6 +55,12 @@ export function parseQuery(search: string): LocationQuery {
     // allow the = character
     let eqPos = searchParam.indexOf('=')
     let key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos))
+
+    // this ignores ?__proto__&toString
+    if (Object.prototype.hasOwnProperty(key)) {
+      continue
+    }
+
     let value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1))
 
     if (key in query) {