Open Bug 1651887 Opened 4 years ago Updated 3 years ago

\n become \r\n in formdata

Categories

(Core :: DOM: Networking, defect, P3)

78 Branch
Desktop
Unspecified
defect

Tracking

()

Tracking Status
firefox78 --- affected

People

(Reporter: reallyimeric, Unassigned)

References

(Depends on 1 open bug)

Details

(Whiteboard: [necko-triaged])

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Steps to reproduce:

fd = new FormData
fd.append('k', 'A\nA')
fetch('/', {method: 'POST', body: fd})

Actual results:

firefox send 'A\r\nA' as the value of key 'k'

Expected results:

firefox send 'A\nA' as the value of key 'k'

This issue is not detailed enough for me to reproduce it. Issues that address the same issue are set to this component. A developer from this component should understand exactly what it means.

Please attach a test case or some more detailed information on how to properly reproduce it if it needs confirmation or verification. Thank you!

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Hardware: Unspecified → Desktop
  1. use any network monitor (e.g., wireshark) to inspect http traffic
  2. send a multipart/formdata POST request at any http site, using dev tool console:
fd = new FormData
fd.append('k', 'A\nA')
fetch('/', {method: 'POST', body: fd})

wireshark shows firefox send 41 0d 0a 41 (that is A\r\nA in utf-8 hex) instead of 41 0a 41

Attached file formdata.zip

I can repro this and am attaching Node.js server script:

  1. Run the script
  2. Access https://localhost:5000/
  3. See the result

Probably better component:

Component: DOM: Core & HTML → DOM: Networking

John, I want to say this is working as expected but don't know that much about FormData so wanted to check with you, who from commits seem to be more familiar with this area.

Flags: needinfo?(jdai)

The FormData appends follows the spec[1], however, the problem may in the fetch request which uses line break converting while constructing fetch request. While constructing a fetch request[2], it will run ExtractByteStreamFromBody[3] then GetSendInfo[4] will use FSMultipartFormData[5] to get form data which will do line break converting[5] at the same time. I also test that Safari and Firefox has the same issue, but Chrome didn't.

[1] https://xhr.spec.whatwg.org/#dom-formdata-append and https://searchfox.org/mozilla-central/rev/cf561cece0ca9aeaf0202e68699836d957d0c670/dom/base/FormData.h#108
[2] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/fetch/Request.cpp#583
[3] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/fetch/Fetch.cpp#888
[4] https://searchfox.org/mozilla-central/rev/cf561cece0ca9aeaf0202e68699836d957d0c670/dom/base/FormData.cpp#318
[5] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/html/HTMLFormSubmission.cpp#391-393

Flags: needinfo?(jdai)
Component: DOM: Networking → DOM: Core & HTML

Hi Michal, per comment 6, this looks more a issue in fetch request code, which per my understanding is within the DOM: Networking module. Can you/your team check again? Thanks.

Flags: needinfo?(michal.novotny)
Component: DOM: Core & HTML → DOM: Networking

I wonder if we have the same issue on form submission with enctype="multipart/form-data"?

Flags: needinfo?(jdai)

(In reply to Edgar Chen [:edgar] from comment #8)

I wonder if we have the same issue on form submition with enctype="multipart/form-data"?

If I read the spec correctly, enctype="multipart/form-data" is one of submit-body[1], hence, it should follow append an entry [2] algorithm which is line break normalization while form submitting.

[1] https://html.spec.whatwg.org/#submit-body
[2] https://html.spec.whatwg.org/#append-an-entry

Flags: needinfo?(jdai)
Depends on: 1657844
Flags: needinfo?(michal.novotny)

Hi John,

It seems that you already know where the problem is. Are you willing to take this bug?
Given the current status of necko team, I think no one has time to work on this.

Flags: needinfo?(jdai)

Sure, I will spend time work on it. Thank you.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(jdai)

(In reply to John Dai[:jdai] from comment #11)

Sure, I will spend time work on it. Thank you.

Thank you!

Assignee: nobody → jdai

I will pick up this bug when I have resouce.

Assignee: jdai → nobody
Severity: -- → S3
Priority: -- → P2
Whiteboard: [necko-triaged]

Whether this is a bug or not is now being reconsidered in the spec: https://github.com/whatwg/html/issues/6469

My bad, I think I read this bug wrong. The issue I linked has nothing to do with the bug. https://github.com/whatwg/html/pull/6287, however, will make Firefox's behavior not a bug.

Priority: P2 → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: