Blame SOURCES/0004-do-not-allow-invalid-hazardous-string-as-section-nam.patch

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