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