You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Core Version: 2.7.4 (Package installed from Arduino IDE board manager)
Development Env: Arduino IDE
Operating System: Windows
Settings in IDE
Module: Generic ESP8266 Module
Flash Mode: dout
Flash Size: 1MB
lwip Variant: v2 Lower Memory
Reset Method: nodemcu
Flash Frequency: 40Mhz
CPU Frequency: 80Mhz
Upload Using: SERIAL
Upload Speed: 3000000
Problem Description
The scenario is uploading a file through an HTML form. This uses a POST request to send multipart form data, although the files I'm using are small enough that they fit within one request buffer (i.e. <2048 bytes). The small program below accepts the file from the form and prints out the buffer contents. This usually works. For my application I am trying to upload new root certificates in X.509 format. This causes a problem because the file contains "-----END CERTIFICATE-----" at the end of the file. In multipart form data, the separator for fields is a line called "boundary," which starts with (at least) two dashes. For example, I'm using FireFox and each form field is separated by some unique string like "-----------------------------26263539015755059383526350366" Here is a link to the relevant section of the library. There is a bug in the logic checking if it is actually the boundary line. In my example I included an extra field below the file entry. When I print the file buffer, it includes the boundary string and the data of the next form entry. If I don't include the extra form entry, the upload hangs while the server waits for the end of the entry.
What is going wrong in the algorithm: You notice the current line starts with two dashes and decide to check if it is the boundary line. You read in enough characters to check if it is the boundary string. However, the actual line is shorter than the boundary string, so you end up reading in the current line plus half of the next one (the actual boundary string). Then you see it does not match the boundary string, so you go back to reading the file. Again you notice two dashes, and read in the length of the boundary string. Since you were already halfway through the line containing the boundary, the stuff you read in doesn't fully match the boundary. So you continue on reading into the next entry until you hit the second entry's boundary, which is handled correctly.
How to fix it: Instead of reading the length of the boundary string, make sure to only read to the end of the current line.
Example Sketch
Here is the file I used for testing: DST_Root_CA_X3.pem
Don't forget to fill in your own WiFi credentials
The boundary parsing in the webserver could end up missing boundaries if the
uploaded file had `--` at the start of the line because it read in the entire boundary
length worth of bytes. Fix by only reading up to either the boundary length or
a newline, avoiding the issue.
Fixes#7542
Platform
Settings in IDE
Problem Description
The scenario is uploading a file through an HTML form. This uses a POST request to send multipart form data, although the files I'm using are small enough that they fit within one request buffer (i.e. <2048 bytes). The small program below accepts the file from the form and prints out the buffer contents. This usually works. For my application I am trying to upload new root certificates in X.509 format. This causes a problem because the file contains "-----END CERTIFICATE-----" at the end of the file. In multipart form data, the separator for fields is a line called "boundary," which starts with (at least) two dashes. For example, I'm using FireFox and each form field is separated by some unique string like "-----------------------------26263539015755059383526350366" Here is a link to the relevant section of the library. There is a bug in the logic checking if it is actually the boundary line. In my example I included an extra field below the file entry. When I print the file buffer, it includes the boundary string and the data of the next form entry. If I don't include the extra form entry, the upload hangs while the server waits for the end of the entry.
What is going wrong in the algorithm: You notice the current line starts with two dashes and decide to check if it is the boundary line. You read in enough characters to check if it is the boundary string. However, the actual line is shorter than the boundary string, so you end up reading in the current line plus half of the next one (the actual boundary string). Then you see it does not match the boundary string, so you go back to reading the file. Again you notice two dashes, and read in the length of the boundary string. Since you were already halfway through the line containing the boundary, the stuff you read in doesn't fully match the boundary. So you continue on reading into the next entry until you hit the second entry's boundary, which is handled correctly.
How to fix it: Instead of reading the length of the boundary string, make sure to only read to the end of the current line.
Example Sketch
Here is the file I used for testing: DST_Root_CA_X3.pem
Don't forget to fill in your own WiFi credentials
Debug Messages
The text was updated successfully, but these errors were encountered: