Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remote memory disclosure with multipart attachments #2018

Closed
wants to merge 1 commit into from
Closed

Fix remote memory disclosure with multipart attachments #2018

wants to merge 1 commit into from

Conversation

feross
Copy link
Contributor

@feross feross commented Jan 19, 2016

If the node process makes a request with a multipart attachment, and the type of the body option is a Number, then that many bytes of uninitialized memory will be sent in the body of the request. Here's an example:

request({
  method: 'POST',
  uri: 'http://localhost:8000',
  multipart: [{ body: 1000 }]
}

And here's a more complete reproducible example:

var http = require('http')
var request = require('request')

http.createServer(function (req, res) {
  var data = ''
  req.setEncoding('utf8')
  req.on('data', function (chunk) {
    console.log('data')
    data += chunk
  })
  req.on('end', function () {
    // this will print uninitialized memory from the client
    console.log('Client sent:\n', data)
  })
  res.end()
}).listen(8000)

request({
  method: 'POST',
  uri: 'http://localhost:8000',
  multipart: [{ body: 1000 }]
},
function (err, res, body) {
  if (err) return console.error('upload failed:', err)
  console.log('sent')
})

This PR fixes the issue by coercing the type of the body option to a string. (An alternate solution would be to throw an exception in this case.)

Further reading:

@feross
Copy link
Contributor Author

feross commented Jan 19, 2016

For the record, I'm sharing this here for the first time since this doesn't seem particularly easy to exploit. That said, it's still probably a good idea to release a fix in a timely manner.

@simov
Copy link
Member

simov commented Jan 20, 2016

Thanks I've added your commit here #2022 + a test case.

@ChALkeR
Copy link
Contributor

ChALkeR commented Jan 20, 2016

@feross

For the record, I'm sharing this here for the first time since this doesn't seem particularly easy to exploit. That said, it's still probably a good idea to release a fix in a timely manner.

It still looks like a much better idea to send those over emails. Can I have a chat with you on IRC or Gitter?

@ChALkeR
Copy link
Contributor

ChALkeR commented Jan 20, 2016

@feross I know of at least one npm module that reads config from a JSON file and sends a multipart request using typed value from that config as the raw body entry of some multipart data to a remote server, using request. And I think that this is much likely to be done in actual setups (aka apps), not only npm modules.

@simov simov closed this in #2022 Jan 21, 2016
@grnd
Copy link

grnd commented Mar 28, 2016

Vulnerable range: <2.68.0 >2.2.5 (total of 77 releases)
There is one version in that range that's not exploitable, 2.47.0 (throws TypeError).
While<=2.2.5 is not vulnerable because part's body is wrapped with '\r\n' just before it is passed to Buffer.

      self.body += '\r\n' + body + '\r\n'
    })
    self.body += '--frontier--'
  }

  if (self.body) {
    if (!Buffer.isBuffer(self.body)) {
      self.body = new Buffer(self.body)
    }

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 28, 2016

@evilaliv3 There are about 14000 of those. Ah, sorry, forgot the lower limit. About 10400.

evilaliv3 added a commit to evilaliv3/registry that referenced this pull request Jul 29, 2016
This update is to address a security vulnerability allowing potential remote memory exposure on request<=2.68

Details:
 - https://snyk.io/vuln/npm:request:20160119
 - request/request#2018
evilaliv3 added a commit to evilaliv3/node-request-replay that referenced this pull request Jul 29, 2016
evilaliv3 added a commit to evilaliv3/node-request-replay that referenced this pull request Jul 29, 2016
This update is to address a security vulnerability allowing potential remote memory exposure on request<=2.68

Details:
 - https://snyk.io/vuln/npm:request:20160119
 - request/request#2018
evilaliv3 added a commit to evilaliv3/npm-registry-client that referenced this pull request Jul 31, 2016
This update is to address a security vulnerability allowing potential remote memory exposure on request<=2.68

Details:
 - https://snyk.io/vuln/npm:request:20160119
 - request/request#2018
julkue pushed a commit to bower/registry that referenced this pull request Sep 9, 2016
This update is to address a security vulnerability allowing potential remote memory exposure on request<=2.68

Details:
 - https://snyk.io/vuln/npm:request:20160119
 - request/request#2018
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
robocop bot referenced this pull request in goeltanmay/PatientsApp Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants