jshttp / proxy-addr

Determine address of proxied request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trying to modify passed in values

elmigranto opened this issue · comments

I have my configuration options in deeply frozen object, so I do not accidentaly modify them and use new ones somewhere else. When setting trust proxy from that config object, proxy-addr tries to modify it.

Versions I have are express@4.15.3 and proxy-addr@1.1.4. The fix might be to .slice() it first:

   var trust = trustArg.slice();

Relevant stacktrace frames:

<project>/node_modules/proxy-addr/index.js:106
    trust.splice.apply(trust, [i, 1].concat(val));
                 ^

TypeError: Cannot add/remove sealed array elements
    at Array.splice (<anonymous>)
    at Function.compile (<project>/node_modules/proxy-addr/index.js:106:18)
    at exports.compileTrust (<project>/node_modules/express/lib/utils.js:250:20)
    at Function.set (<project>/node_modules/express/lib/application.js:372:34)
    <  omitted  >

For now I just use CSV entry instead of array ('addr1, addr2' instead of ['addr1', 'addr2']).

Yea, definitely a bug; the array should not be getting modified because users may have frozen arrays like you or even just want to re-use that array for something else.