110-CVE-2018-1000007.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. From af32cd3859336ab963591ca0df9b1e33a7ee066b Mon Sep 17 00:00:00 2001
  2. From: Daniel Stenberg <daniel@haxx.se>
  3. Date: Fri, 19 Jan 2018 13:19:25 +0100
  4. Subject: [PATCH] http: prevent custom Authorization headers in redirects
  5. ... unless CURLOPT_UNRESTRICTED_AUTH is set to allow them. This matches how
  6. curl already handles Authorization headers created internally.
  7. Note: this changes behavior slightly, for the sake of reducing mistakes.
  8. Added test 317 and 318 to verify.
  9. Reported-by: Craig de Stigter
  10. Bug: https://curl.haxx.se/docs/adv_2018-b3bf.html
  11. ---
  12. docs/libcurl/opts/CURLOPT_HTTPHEADER.3 | 12 +++-
  13. lib/http.c | 10 ++-
  14. lib/setopt.c | 2 +-
  15. lib/urldata.h | 2 +-
  16. tests/data/Makefile.inc | 2 +-
  17. tests/data/test317 | 94 +++++++++++++++++++++++++
  18. tests/data/test318 | 95 ++++++++++++++++++++++++++
  19. 7 files changed, 212 insertions(+), 5 deletions(-)
  20. create mode 100644 tests/data/test317
  21. create mode 100644 tests/data/test318
  22. --- a/docs/libcurl/opts/CURLOPT_HTTPHEADER.3
  23. +++ b/docs/libcurl/opts/CURLOPT_HTTPHEADER.3
  24. @@ -5,7 +5,7 @@
  25. .\" * | (__| |_| | _ <| |___
  26. .\" * \___|\___/|_| \_\_____|
  27. .\" *
  28. -.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
  29. +.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  30. .\" *
  31. .\" * This software is licensed as described in the file COPYING, which
  32. .\" * you should have received as part of this distribution. The terms
  33. @@ -77,6 +77,16 @@ the headers. They may be private or othe
  34. Use \fICURLOPT_HEADEROPT(3)\fP to make the headers only get sent to where you
  35. intend them to get sent.
  36. +
  37. +Custom headers are sent in all requests done by the easy handles, which
  38. +implies that if you tell libcurl to follow redirects
  39. +(\fBCURLOPT_FOLLOWLOCATION(3)\fP), the same set of custom headers will be sent
  40. +in the subsequent request. Redirects can of course go to other hosts and thus
  41. +those servers will get all the contents of your custom headers too.
  42. +
  43. +Starting in 7.58.0, libcurl will specifically prevent "Authorization:" headers
  44. +from being sent to other hosts than the first used one, unless specifically
  45. +permitted with the \fBCURLOPT_UNRESTRICTED_AUTH(3)\fP option.
  46. .SH DEFAULT
  47. NULL
  48. .SH PROTOCOLS
  49. --- a/lib/http.c
  50. +++ b/lib/http.c
  51. @@ -725,7 +725,7 @@ Curl_http_output_auth(struct connectdata
  52. if(!data->state.this_is_a_follow ||
  53. conn->bits.netrc ||
  54. !data->state.first_host ||
  55. - data->set.http_disable_hostname_check_before_authentication ||
  56. + data->set.allow_auth_to_other_hosts ||
  57. strcasecompare(data->state.first_host, conn->host.name)) {
  58. result = output_auth_headers(conn, authhost, request, path, FALSE);
  59. }
  60. @@ -1624,6 +1624,14 @@ CURLcode Curl_add_custom_headers(struct
  61. checkprefix("Transfer-Encoding:", headers->data))
  62. /* HTTP/2 doesn't support chunked requests */
  63. ;
  64. + else if(checkprefix("Authorization:", headers->data) &&
  65. + /* be careful of sending this potentially sensitive header to
  66. + other hosts */
  67. + (data->state.this_is_a_follow &&
  68. + data->state.first_host &&
  69. + !data->set.allow_auth_to_other_hosts &&
  70. + !strcasecompare(data->state.first_host, conn->host.name)))
  71. + ;
  72. else {
  73. CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n",
  74. headers->data);
  75. --- a/lib/url.c
  76. +++ b/lib/url.c
  77. @@ -972,7 +972,7 @@ CURLcode Curl_setopt(struct Curl_easy *d
  78. * Send authentication (user+password) when following locations, even when
  79. * hostname changed.
  80. */
  81. - data->set.http_disable_hostname_check_before_authentication =
  82. + data->set.allow_auth_to_other_hosts =
  83. (0 != va_arg(param, long)) ? TRUE : FALSE;
  84. break;
  85. --- a/lib/urldata.h
  86. +++ b/lib/urldata.h
  87. @@ -1675,7 +1675,7 @@ struct UserDefined {
  88. bool http_keep_sending_on_error; /* for HTTP status codes >= 300 */
  89. bool http_follow_location; /* follow HTTP redirects */
  90. bool http_transfer_encoding; /* request compressed HTTP transfer-encoding */
  91. - bool http_disable_hostname_check_before_authentication;
  92. + bool allow_auth_to_other_hosts;
  93. bool include_header; /* include received protocol headers in data output */
  94. bool http_set_referer; /* is a custom referer used */
  95. bool http_auto_referer; /* set "correct" referer when following location: */