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