Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate method parameter of HttpClient.open(), check it has no CR, LF #45744

Closed
licy183 opened this issue Apr 18, 2021 · 8 comments
Closed

Validate method parameter of HttpClient.open(), check it has no CR, LF #45744

licy183 opened this issue Apr 18, 2021 · 8 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P3 A lower priority bug or feature request

Comments

@licy183
Copy link

licy183 commented Apr 18, 2021

import 'dart:convert';
import 'dart:io';

void main() {
  HttpClient client = HttpClient();
  client
      .open("GET / HTTP/1.1\r\nHost: example.com\r\n\r\nGET", "example.com",
          80, "/index.html")
      .then((request) => request.close())
      .then((value) => value.toList())
      .then((value) {
    print(utf8.decode(value.fold([], (previousValue, element) {
      previousValue.addAll(element);
      return previousValue;
    })));
  });
}

The code above will generate a Http Request which looks like the following.

GET / HTTP/1.1
HOST: EXAMPLE.COM

GET /index.html HTTP/1.1
user-agent: Dart/2.12 (dart:io)
test: test
accept-encoding: gzip
content-length: 0
host: example.com

This request will let the server response twice and make the HttpClient throws an exception.

Unhandled exception:
HttpException: Unexpected response (unsolicited response without request).

And this will cause a CRLF injection.
Related Issue: cfug/dio#1130

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Apr 19, 2021
@a-siva
Copy link
Contributor

a-siva commented Apr 20, 2021

/cc @aam

@a-siva a-siva added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Apr 20, 2021
@aam
Copy link
Contributor

aam commented Apr 20, 2021

If I understand CRLF injection correctly assumption is that some unexpected code gets in the middle between client and server and updates method of the HTTP request with headers separated by CRLF.
In this example, though, all of the code lives in one client dart application - how some code is expected to get in the middle?
If it is the developer who writes such code that adds headers to the method parameter, how that would be different from that developer actually using headers field of HttpClientRequest produced by HttpClient.open?

@licy183
Copy link
Author

licy183 commented Apr 21, 2021

The RFC-2616 on Page 35, states the following:

The Request-Line begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF. The elements are separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.
Request-Line = Method SP Request-URI SP HTTP-Version CRLF

According to this, maybe it is better to check the method parameter to ensure that it contains neither CR('\r') nor LF('\n').

@aam aam added P3 A lower priority bug or feature request and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels Apr 21, 2021
@aam
Copy link
Contributor

aam commented Apr 21, 2021

Yeah, we could add such a check. That would be a breaking change I imagine.
Lowering to P3 from P1.

@aam aam changed the title HttpClient.open(String method, ...) method seems to be injectable Validate method parameter of HttpClient.open(), check it has no CR, LF May 6, 2021
@flbaue
Copy link

flbaue commented Mar 10, 2022

I just noticed this issue because dio has a CVE entry about this: https://nvd.nist.gov/vuln/detail/CVE-2021-31402 which is scored as high.
How do you estimate the risk of this?

@aam
Copy link
Contributor

aam commented Mar 10, 2022

Unless I am missing something it's dart code itself that sends a request that also controls the method name. There is nowhere for attacker to insert itself so they update method name maliciously. Because of that I think the risk is non-existent/low.

Still though, validating that method argument(https://github.com/dart-lang/sdk/blob/main/sdk/lib/_http/http.dart#L1380 and https://github.com/dart-lang/sdk/blob/main/sdk/lib/_http/http.dart#L1395 has no CRLF makes sense.

cc @brianquinlan

@mkranus
Copy link

mkranus commented Aug 26, 2022

@aam @brianquinlan What is the progress on this? German regulators have caught up to this problem due to CVE priority. Please either fix this, or negotiate with CVE to revert.

@aam
Copy link
Contributor

aam commented Aug 26, 2022

Looks like it slipped through the cracks.
https://dart-review.googlesource.com/c/sdk/+/256429 should address the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

6 participants