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