ciaranj / node-oauth

OAuth wrapper for node.js
MIT License
2.44k stars 660 forks source link

Invalid character in header content ["clean"] - because of using `for...in`? #372

Closed OfirD1 closed 1 year ago

OfirD1 commented 1 year ago

I'm using node-oauth through other third party library (passport), and get the following error:

Invalid character in header content ["clean"]

This is caused by this code block in oauth2js:

var realHeaders= {};
for( var key in this._customHeaders ) {
  realHeaders[key]= this._customHeaders[key];
}

I took a picture of my Watch window while debugging this, and we can see that realHeaders got the function clean from the prototype of this._customHeaders:

image

Here's my full stack trace (my local paths are redacted):

error: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["clean"]
   at ClientRequest.setHeader (node:_http_outgoing:578:3)
   at new ClientRequest (node:_http_client:266:14)
   at Object.request (node:https:333:10)
   at exports.OAuth2._executeRequest (...\node_modules\oauth\lib\oauth2.js:146:30)
   at exports.OAuth2._request (...\node_modules\oauth\lib\oauth2.js:120:8)
   at exports.OAuth2.getOAuthAccessToken (...\node_modules\oauth\lib\oauth2.js:190:8)
   at loaded (...\node_modules\passport-oauth2\lib\strategy.js:175:20)
   at NullStore.verify (...\node_modules\passport-oauth2\lib\state\null.js:9:3)
   at Strategy.OAuth2Strategy.authenticate (...\node_modules\passport-oauth2\lib\strategy.js:222:26)
   at attempt (...\node_modules\passport\lib\middleware\authenticate.js:369:16)
error: $GET /api/auth/stack-exchange/callback?code=...)) 500 - 10.371 ms - message: Invalid character in header content ["clean"]

Have I done anything wrong, or should this be fixed?

OfirD1 commented 1 year ago

My bad 🤦‍♂️ I had Object.prototype.clean in my app.