You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.4 KiB

  1. commit 41898a216e92c80c1354b67613834be1b3e97864
  2. Author: Willy Tarreau <w@1wt.eu>
  3. Date: Fri Oct 25 14:16:14 2019 +0200
  4. MINOR: config: warn on presence of "\n" in header values/replacements
  5. Yves Lafon reported an interesting case where an old rsprep rule used
  6. to conditionally append a header field by inserting a \n in the exising
  7. value was breaking H2 in HTX mode, with the browser rightfully reporting
  8. a PROTOCOL_ERROR when facing the \n. In legacy mode, since the response
  9. is first parsed again as an HTTP/1 message before being converted to H2
  10. the issue does not happen. We should definitely discourage from using
  11. this old trick nowadays, http-request and http-response rules were made
  12. exactly to end this. Let's detect this and emit a warning when present.
  13. In 2.0 there is already a warning recalling that these rules are
  14. deprecated and which explains what to do instead, so the user now gets
  15. all the relevant information to convert them.
  16. There is no upstream commit ID for this patch because these rules were
  17. indeed removed from 2.1. This patch could be backported to 1.9 as it
  18. can also trigger the problem when HTX is enabled.
  19. diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
  20. index 5454f3bb..9c3e107a 100644
  21. --- a/src/cfgparse-listen.c
  22. +++ b/src/cfgparse-listen.c
  23. @@ -294,6 +294,12 @@ static int create_cond_regex_rule(const char *file, int line,
  24. goto err_free;
  25. }
  26. + if (repl && strchr(repl, '\n')) {
  27. + ha_warning("parsing [%s:%d] : '%s' : hack involving '\\n' character in replacement string will fail with HTTP/2.\n",
  28. + file, line, cmd);
  29. + ret_code |= ERR_WARN;
  30. + }
  31. +
  32. if (dir == SMP_OPT_DIR_REQ && warnif_misplaced_reqxxx(px, file, line, cmd))
  33. ret_code |= ERR_WARN;
  34. @@ -4039,6 +4045,12 @@ stats_error_parsing:
  35. goto out;
  36. }
  37. + if (strchr(args[1], '\n')) {
  38. + ha_warning("parsing [%s:%d] : '%s' : hack involving '\\n' character in new header value will fail with HTTP/2.\n",
  39. + file, linenum, args[0]);
  40. + err_code |= ERR_WARN;
  41. + }
  42. +
  43. wl = calloc(1, sizeof(*wl));
  44. wl->cond = cond;
  45. wl->s = strdup(args[1]);
  46. @@ -4157,6 +4169,12 @@ stats_error_parsing:
  47. goto out;
  48. }
  49. + if (strchr(args[1], '\n')) {
  50. + ha_warning("parsing [%s:%d] : '%s' : hack involving '\\n' character in new header value will fail with HTTP/2.\n",
  51. + file, linenum, args[0]);
  52. + err_code |= ERR_WARN;
  53. + }
  54. +
  55. wl = calloc(1, sizeof(*wl));
  56. wl->cond = cond;
  57. wl->s = strdup(args[1]);