You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ni...@apache.org on 2020/06/06 22:54:32 UTC

svn commit: r1878553 - /httpd/httpd/trunk/modules/filters/mod_proxy_html.c

Author: niq
Date: Sat Jun  6 22:54:32 2020
New Revision: 1878553

URL: http://svn.apache.org/viewvc?rev=1878553&view=rev
Log:
PR#64443: watch whether mod_proxy_html i18n might risk messing up FORM
submission, and insert accept-charset attribute if necessary.

Modified:
    httpd/httpd/trunk/modules/filters/mod_proxy_html.c

Modified: httpd/httpd/trunk/modules/filters/mod_proxy_html.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_proxy_html.c?rev=1878553&r1=1878552&r2=1878553&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_proxy_html.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_proxy_html.c Sat Jun  6 22:54:32 2020
@@ -417,6 +417,9 @@ static void pstartElement(void *ctxt, co
     const char** attrs = (const char**) uattrs;
     const htmlElemDesc* desc = htmlTagLookup(uname);
     urlmap *themap = ctx->map;
+    const char *accept_charset = NULL;
+
+
 #ifdef HAVE_STACK
     const void** descp;
 #endif
@@ -446,6 +449,21 @@ static void pstartElement(void *ctxt, co
     /* TODO - implement HTML "allowed here" */
 #endif
 
+    /* PR#64443: for <FORM>, insert accept-charset attribute if necessary
+     * It's necessary if we've changed the charset (i.e. input not UTF-8)
+     *  UNLESS someone has taken charge.
+     * If there's already an accept-charset, then the backend is in charge.
+     * If ProxyHTMLCharsetOut is set, the sysop has taken charge.
+     */
+    if ((xml2enc_charset != NULL) && (ctx->cfg->charset_out == NULL)
+        && !strcasecmp(name, "FORM")) {
+        xmlCharEncoding enc;
+        if ((xml2enc_charset(ctx->f->r, &enc, &accept_charset) != APR_SUCCESS)
+            || (enc == XML_CHAR_ENCODING_UTF8)) {
+            accept_charset = NULL;  /* Now pay attention if not NULL */
+        }
+    }
+
     ap_fputc(ctx->f->next, ctx->bb, '<');
     ap_fputs(ctx->f->next, ctx->bb, name);
 
@@ -672,8 +690,17 @@ static void pstartElement(void *ctxt, co
                 pcharacters(ctx, (const xmlChar*)ctx->buf, strlen(ctx->buf));
                 ap_fputc(ctx->f->next, ctx->bb, '"');
             }
+            /* PR#64443: watch for accept-charset from backend */
+            if (accept_charset && !strcasecmp(a[0], "accept-charset")) {
+                accept_charset = NULL;
+            }
         }
     }
+    /* PR#64443: we've seen all we need, so add accept-charset if necessary */
+    if (accept_charset != NULL) {
+        ap_fprintf(ctx->f->next, ctx->bb, " accept-charset=\"%s\"",
+                   accept_charset);
+    }
     ctx->offset = 0;
     if (desc && desc->empty)
         ap_fputs(ctx->f->next, ctx->bb, ctx->etag);