fe953d
From cdd56e89bf13b495e5b97cc4416f61638617d7f4 Mon Sep 17 00:00:00 2001
fe953d
From: isaacs <i@izs.me>
fe953d
Date: Tue, 8 Dec 2020 14:21:50 -0800
fe953d
Subject: [PATCH] do not allow invalid hazardous string as section name
fe953d
fe953d
Signed-off-by: rpm-build <rpm-build>
fe953d
---
fe953d
 deps/npm/node_modules/ini/ini.js        |  8 +++++
fe953d
 deps/npm/node_modules/ini/test/proto.js | 45 +++++++++++++++++++++++++
fe953d
 2 files changed, 53 insertions(+)
fe953d
 create mode 100644 deps/npm/node_modules/ini/test/proto.js
fe953d
fe953d
diff --git a/deps/npm/node_modules/ini/ini.js b/deps/npm/node_modules/ini/ini.js
fe953d
index 590195d..0401258 100644
fe953d
--- a/deps/npm/node_modules/ini/ini.js
fe953d
+++ b/deps/npm/node_modules/ini/ini.js
fe953d
@@ -80,6 +80,12 @@ function decode (str) {
fe953d
     if (!match) return
fe953d
     if (match[1] !== undefined) {
fe953d
       section = unsafe(match[1])
fe953d
+      if (section === '__proto__') {
fe953d
+        // not allowed
fe953d
+        // keep parsing the section, but don't attach it.
fe953d
+        p = {}
fe953d
+        return
fe953d
+      }
fe953d
       p = out[section] = out[section] || {}
fe953d
       return
fe953d
     }
fe953d
@@ -94,6 +100,7 @@ function decode (str) {
fe953d
     // Convert keys with '[]' suffix to an array
fe953d
     if (key.length > 2 && key.slice(-2) === '[]') {
fe953d
       key = key.substring(0, key.length - 2)
fe953d
+      if (key === '__proto__') return
fe953d
       if (!p[key]) {
fe953d
         p[key] = []
fe953d
       } else if (!Array.isArray(p[key])) {
fe953d
@@ -125,6 +132,7 @@ function decode (str) {
fe953d
     var l = parts.pop()
fe953d
     var nl = l.replace(/\\\./g, '.')
fe953d
     parts.forEach(function (part, _, __) {
fe953d
+      if (part === '__proto__') return
fe953d
       if (!p[part] || typeof p[part] !== 'object') p[part] = {}
fe953d
       p = p[part]
fe953d
     })
fe953d
diff --git a/deps/npm/node_modules/ini/test/proto.js b/deps/npm/node_modules/ini/test/proto.js
fe953d
new file mode 100644
fe953d
index 0000000..ab35533
fe953d
--- /dev/null
fe953d
+++ b/deps/npm/node_modules/ini/test/proto.js
fe953d
@@ -0,0 +1,45 @@
fe953d
+var ini = require('../')
fe953d
+var t = require('tap')
fe953d
+
fe953d
+var data = `
fe953d
+__proto__ = quux
fe953d
+foo = baz
fe953d
+[__proto__]
fe953d
+foo = bar
fe953d
+[other]
fe953d
+foo = asdf
fe953d
+[kid.__proto__.foo]
fe953d
+foo = kid
fe953d
+[arrproto]
fe953d
+hello = snyk
fe953d
+__proto__[] = you did a good job
fe953d
+__proto__[] = so you deserve arrays
fe953d
+thanks = true
fe953d
+`
fe953d
+var res = ini.parse(data)
fe953d
+t.deepEqual(res, {
fe953d
+  foo: 'baz',
fe953d
+  other: {
fe953d
+    foo: 'asdf',
fe953d
+  },
fe953d
+  kid: {
fe953d
+    foo: {
fe953d
+      foo: 'kid',
fe953d
+    },
fe953d
+  },
fe953d
+  arrproto: {
fe953d
+    hello: 'snyk',
fe953d
+    thanks: true,
fe953d
+  },
fe953d
+})
fe953d
+t.equal(res.__proto__, Object.prototype)
fe953d
+t.equal(res.kid.__proto__, Object.prototype)
fe953d
+t.equal(res.kid.foo.__proto__, Object.prototype)
fe953d
+t.equal(res.arrproto.__proto__, Object.prototype)
fe953d
+t.equal(Object.prototype.foo, undefined)
fe953d
+t.equal(Object.prototype[0], undefined)
fe953d
+t.equal(Object.prototype['0'], undefined)
fe953d
+t.equal(Object.prototype[1], undefined)
fe953d
+t.equal(Object.prototype['1'], undefined)
fe953d
+t.equal(Array.prototype[0], undefined)
fe953d
+t.equal(Array.prototype[1], undefined)
fe953d
-- 
fe953d
2.29.2
fe953d