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

[IOS] "fetch + FormData" create the Content-Type with a boundary wrapped with delimiter " #7564

Closed
XuChangZJU opened this issue May 14, 2016 · 8 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@XuChangZJU
Copy link

XuChangZJU commented May 14, 2016

When I attempt to upload file using the fetch + FormData, Android plays well and IOS always fails. After monitoring the http request, I found that IOS creates the http request as follows:

100144153633240385

the boundary in the content-type is wrapped with delimiter "
and this is the android's:

712435250518463508

This is probably cause by the code in _react-native/Libraries/Network/RCTNetworking.m_line 117

https://github.com/facebook/react-native/blob/5723915eaacfd3d8a8a7165c550f1fb9316c15ad/Libraries/Network/RCTNetworking.m

Another little problem is that ios does not add "content-length" for each part.

@lacker
Copy link
Contributor

lacker commented Oct 21, 2016

Can you reproduce this problem on a small sample app with a rnplay.org link?

saleehk added a commit to saleehk/react-native that referenced this issue Nov 11, 2016
Fix for some firewall with ModSecurity
 rules for MULTIPART_STRICT_ERROR, namely MULTIPART_BOUNDARY_QUOTED.
@saleehk
Copy link
Contributor

saleehk commented Nov 11, 2016

@lacker @XuChangZJU I happened to have the same issue. It happened only on some servers where 'ModSecurity' is enabled, and MULTIPART_BOUNDARY_QUOTED rule is added in same. What it saying is that we have to remove the "'" on sending boundary for example

boundary="some_value"

to

 boundary=some_value 

In Libraries/Network/RCTNetworking.mm there

 NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=\"%@\"", _boundary];

when i change to

 NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", _boundary];

then compiled then run and its working perfect,I have made pull request too
#10876

@li-yechao
Copy link

li-yechao commented Dec 7, 2016

not work if boundary include slash

// koa request.js (line 548)
  is(types) {
    if (!types) return typeis(this.req);
    if (!Array.isArray(types)) types = [].slice.call(arguments);
    return typeis(this.req, types);
  }

// type-is index.js (line 237)
function normalizeType (value) {
  // parse the type
  var type = typer.parse(value)

  // remove the parameters
  type.parameters = undefined

  // reformat it
  return typer.format(type)
}

// media-typer
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;

jshttp/media-typer#5
The / is an illegal character for Content-Type, which is what this module parses. The boundary parameter value needs to be quoted if it contains a / character, for example:

multipart/form-data; boundary="b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o"

may the quote is necessary

@kfiroo
Copy link

kfiroo commented Dec 11, 2016

@unordered I'm having the same issue, any workaround for that until this is resolved?

@li-yechao
Copy link

@kfiroo
Copy link

kfiroo commented Dec 12, 2016

@unordered Thanks! I +1ed it before, just was wondering if we have some client side work around until react-native fix will land.
Currently I'm patching the header on the server side - something like that if anyone is interested
Using node + express

// HACK - react-native generates FormData with an invalid boundary that might contain '/'
// we need to wrap the boundary value with quotes to fix it
// TODO - remove this when react-native releases the fix
var re = /^multipart\/form-data.\s?boundary=['"]?(.*?)['"]?$/i;
app.use(function (req, res, next) {
    var contentType = req.headers['content-type'];
    var match = re.exec(contentType);
    if (match && match.length === 2) {
        req.headers['content-type'] = 'multipart/form-data; boundary="' + match[1] + '"';
    }
    next();
});

DanielMSchmidt pushed a commit to DanielMSchmidt/react-native that referenced this issue Jan 4, 2017
Summary:
Fix for some firewall with ModSecurity
 rules for MULTIPART_STRICT_ERROR, namely MULTIPART_BOUNDARY_QUOTED.
Closes facebook#10876

Reviewed By: javache

Differential Revision: D4176229

Pulled By: ericvicenti

fbshipit-source-id: 8db819bd3e9b23fa3c1802c48091bb4c44358381
@th317erd
Copy link

th317erd commented Feb 7, 2017

This is also an issue for me. When will the official fix land? Anyone? Never mind, I see it made it into RN-0.41. Thanks!

@nickjanssen
Copy link

nickjanssen commented Feb 9, 2017

This bug is still present in 0.41.2
EDIT: I forgot to recompile. Working great!!

For now @kfiroo 's fix works great though, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants