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.

105 lines
4.1 KiB

  1. From 57ab20ace504fdb6e0944ef6fa6e0ce35adc4446 Mon Sep 17 00:00:00 2001
  2. From: Glenn Strauss <gstrauss@gluelogic.com>
  3. Date: Sun, 26 Feb 2017 17:49:47 -0500
  4. Subject: [PATCH] [mod_cgi] cgi.local-redir = [enable|disable] (#2108, #2793)
  5. new directive cgi.local-redir = [enable|disable]
  6. *disable* RFC3875 6.2.2 local-redir by default.
  7. (behavior change from when local-redir support added in lighttpd 1.4.40)
  8. The reason for this behavior change is that CGI local-redir support
  9. (RFC3875 6.2.2) is an optimization. Absence of support may result in
  10. additional latency in servicing a request due the additional round-trip
  11. to the client, but that was the prior behavior (before lighttpd 1.4.40)
  12. and is the behavior of web servers which do not support CGI local-redir.
  13. However, enabling CGI local-redir by default may result in broken links
  14. in the case where a user config (unaware of CGI local-redir behavior)
  15. returns HTML pages containing *relative* paths (not root-relative paths)
  16. which are relative to the location of the local-redir target document,
  17. and the local-redir target document is located at a different URL-path
  18. from the original CGI request.
  19. x-ref:
  20. RFC3875 CGI 1.1 specification section 6.2.2 Local Redirect Response
  21. http://www.ietf.org/rfc/rfc3875
  22. "CGI local redirect not implemented correctly"
  23. https://redmine.lighttpd.net/issues/2108
  24. "1.4.40 regression: broken redirect (using Location) between url.rewrite-once URLs"
  25. https://redmine.lighttpd.net/issues/2793
  26. ---
  27. src/mod_cgi.c | 9 ++++++++-
  28. tests/lighttpd.conf | 1 +
  29. 2 files changed, 9 insertions(+), 1 deletion(-)
  30. --- a/src/mod_cgi.c
  31. +++ b/src/mod_cgi.c
  32. @@ -66,6 +66,7 @@ typedef struct {
  33. typedef struct {
  34. array *cgi;
  35. unsigned short execute_x_only;
  36. + unsigned short local_redir;
  37. unsigned short xsendfile_allow;
  38. array *xsendfile_docroot;
  39. } plugin_config;
  40. @@ -172,6 +173,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_default
  41. { "cgi.execute-x-only", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
  42. { "cgi.x-sendfile", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
  43. { "cgi.x-sendfile-docroot", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 3 */
  44. + { "cgi.local-redir", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 4 */
  45. { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET}
  46. };
  47. @@ -189,6 +191,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_default
  48. s->cgi = array_init();
  49. s->execute_x_only = 0;
  50. + s->local_redir = 0;
  51. s->xsendfile_allow= 0;
  52. s->xsendfile_docroot = array_init();
  53. @@ -196,6 +199,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_default
  54. cv[1].destination = &(s->execute_x_only);
  55. cv[2].destination = &(s->xsendfile_allow);
  56. cv[3].destination = s->xsendfile_docroot;
  57. + cv[4].destination = &(s->local_redir);
  58. p->config_storage[i] = s;
  59. @@ -549,7 +553,7 @@ static int cgi_demux_response(server *sr
  60. * to same URL, since CGI should have handled it internally if it
  61. * really wanted to do that internally)
  62. */
  63. - if (con->http_status >= 300 && con->http_status < 400) {
  64. + if (hctx->conf.local_redir && con->http_status >= 300 && con->http_status < 400) {
  65. /*(con->parsed_response & HTTP_LOCATION)*/
  66. size_t ulen = buffer_string_length(con->uri.path);
  67. data_string *ds;
  68. @@ -1321,6 +1325,7 @@ static int mod_cgi_patch_connection(serv
  69. PATCH(cgi);
  70. PATCH(execute_x_only);
  71. + PATCH(local_redir);
  72. PATCH(xsendfile_allow);
  73. PATCH(xsendfile_docroot);
  74. @@ -1340,6 +1345,8 @@ static int mod_cgi_patch_connection(serv
  75. PATCH(cgi);
  76. } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.execute-x-only"))) {
  77. PATCH(execute_x_only);
  78. + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.local-redir"))) {
  79. + PATCH(local_redir);
  80. } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.x-sendfile"))) {
  81. PATCH(xsendfile_allow);
  82. } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.x-sendfile-docroot"))) {
  83. --- a/tests/lighttpd.conf
  84. +++ b/tests/lighttpd.conf
  85. @@ -110,6 +110,7 @@ fastcgi.server = (
  86. ) ),
  87. )
  88. +cgi.local-redir = "enable"
  89. cgi.assign = (
  90. ".pl" => env.PERL,
  91. ".cgi" => env.PERL,