Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/targets/shell/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

const util = require('util')
const helpers = require('../../helpers/shell')
const headerHelpers = require('../../helpers/headers')
const CodeBuilder = require('../../helpers/code-builder')

module.exports = function (source, options) {
Expand Down Expand Up @@ -39,6 +40,22 @@ module.exports = function (source, options) {
code.push(opts.short ? '-0' : '--http1.0')
}

// if multipart form data, we want to remove the boundary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #226, we discussed just scoping this to fixing cURL due to how cURL handles --form vs raw data.

Did you attempt any kind of audit of other targets to see if they are impacted by similar issues?

Copy link
Member Author

@nateslo nateslo Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not investigate any other targets yet, this fix only pertains to curl multipart

if (source.postData.mimeType === 'multipart/form-data') {
const contentTypeHeaderName = headerHelpers.getHeaderName(source.headersObj, 'content-type')
const contentTypeHeader = source.headersObj[contentTypeHeaderName]

if (contentTypeHeaderName && contentTypeHeader) {
// remove the leading semi colon and boundary
// up to the next semi colon or the end of string
const noBoundary = contentTypeHeader.replace(/; boundary.+?(?=(;|$))/, '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked these regex and functions as expected.

Screen Shot 2021-09-03 at 11 16 37 AM


// replace the content-type header with no boundary in both headersObj and allHeaders
source.headersObj[contentTypeHeaderName] = noBoundary
source.allHeaders[contentTypeHeaderName] = noBoundary
}
}

// construct headers
Object.keys(source.headersObj).sort().forEach(function (key) {
const header = util.format('%s: %s', key, source.headersObj[key])
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/curl/multipart-data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl --request POST \
--url http://mockbin.com/har \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--header 'content-type: multipart/form-data' \
--form [email protected]
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/curl/multipart-file.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl --request POST \
--url http://mockbin.com/har \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--header 'content-type: multipart/form-data' \
--form foo=@test/fixtures/files/hello.txt
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/curl/multipart-form-data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl --request POST \
--url http://mockbin.com/har \
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
--header 'Content-Type: multipart/form-data' \
--form foo=bar