Blanks in query strings not allowed anymore, HTTP 403 forbidden, "Rewritten query string contains control characters or spaces" (Apache CVE-2023-25690)

Created on 13 March 2023, over 1 year ago
Updated 11 July 2024, about 2 months ago

Problem/Motivation

Up until March 10th 2023, Ubuntu's Apache accepted blanks in rewritten query strings.

Since the fix for CVE-2023-25690, they are not allowed anymore.
Other distros will see similar effects sooner or later, when they use Apache HTTPd >=2.4.56 (or backports of this fix in older versions).

A context filter's default setup is to leave filter strings as they are, i.e. allow blanks as well.
This leads to a HTTP 403 "forbidden" when visiting filtered views with a filter with a blank in it.

Steps to reproduce

Create content
Tag it with a term with blanks
Create a view with a context filter that filters content per taxonomy term
Use the view's filter with a term with blanks
Get HTTP 403
Apache logs say:
Rewritten query string contains control characters or spaces

Proposed resolution

I don't know how to properly solve this.
https://stackoverflow.com/questions/75684314/ah10411-error-managing-spac...
says there is a flag for Apache's mod_rewrite ([B]) that might solve it. I am not sure however whether this might affect other functionality as well and opted not to change Drupal's default .htaccess.

I used a workaround in the context filter: Convert all blanks to dashes.

The current default config (of .htaccess and view config) leads to errors, so something needs to be changed, one way or the other, to make this work without errors. Or at least some help text should be added in the context filter's config to warn this could happen though I don't feel that's sufficient.

Please note the error states [..]contains control characters or spaces so this might as well have similar effects with control characters that might be added. I don't know if this can also happen.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 25 minutes ago

Created by

πŸ‡¦πŸ‡ΉAustria tgoeg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @tgoeg
  • πŸ‡ΊπŸ‡ΈUnited States cilefen
  • πŸ‡¦πŸ‡ΉAustria tgoeg

    This has a much bigger impact than I thought.
    It also happens for uploaded images (with blanks in them) when editing a node, so this is not only affecting views.
    The linked-to image works, but the derived image style does not get generated properly.
    The upload directy leads to the same error in apache's error log.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    For funny reasons, I came across this on a deprecated Drupal 6 (!) customer project, where the autocomplete (/nodereference/autocomplete/FIELD/xx yy) didn't work anymore. Crazy to see the impact on the web. And probably on all Drupal version?

    Apache log also reported AH10411: Rewritten query string contains control characters or spaces
    So I guess this is something that has to be fixed in the .htaccess?

    Looks like changing the Drupal 6 RewriteRule from
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    to
    RewriteRule ^(.*)$ index.php?q=$1 [B,L,QSA]
    in .htaccess fixes the issue, but I'm not sure yet about possible side effects. We should also look into Drupal 7!

  • πŸ‡ΊπŸ‡ΈUnited States dww

    This is clearly not specific to Views. Making the title more broad and changing component to "base system" to expand to the more accurate scope.

    Writing automated tests for this will be hard since seeing it break depends on a specific Apache version. DrupalCI is currently using 2.4.54 (from what I can tell). Guess we can have tests to ensure we never put a blank space in a query string or something. Basically, try to get our tests to enforce what Apache >= 2.5.56 is requiring.

    But yeah, this seems like a very big, potentially very disruptive change. 😬

  • πŸ‡¦πŸ‡ΉAustria tgoeg

    Keep in mind lots of distros tend to stay at the package version (down to patch level) of the initial release (and be that 10 years old; looking at you, RedHat!) and only patch in/backport stuff like this.
    No distro-specific package version will ever tell you whether it actually incorporates the fix of the official 2.5.56.

    This makes life of a sysadmin/security guy so much fun.
    (Use Gentoo, and you mostly get what it says on the package (pun intended) :-) )

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    While we analyze this I informed our hosting company to be on the lookout.

  • πŸ‡ΊπŸ‡ΈUnited States johns996 Marquette, MI

    I noticed this impacting media uploads on all of my multisites. Those sites all use a RewriteRule similar to the one listed in #4.

    RewriteRule ^(.*)$ /site/index.php?q=$1 [L,QSA]

    Updating that to add the [B] flag (escape backreferences) fixed the issue.

    RewriteRule ^(.*)$ /site/index.php?q=$1 [B,L,QSA]

    I didn't find another place in the .htaccess that needed the [B] flag added and the changes I made were all exclusive to a multisite install. Was there something I missed?

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Here is the documentation of that rewrite flag: https://httpd.apache.org/docs/current/rewrite/flags.html#flag_b

  • πŸ‡ΊπŸ‡ΈUnited States hunmonk

    Hello Drupal community! Been a long time since my last post...

    Just chipping in a little more data here, because I'm facing the same issue with spaces in form autocompletes.

    I was a little nervous to go with the very broad [B,L,QSA] in the rewrite, but a little further down in the doc it says this:

    In 2.4.26 and later, you can limit the escaping to specific characters in backreferences by listing them: [B=#?;]. Note: The space character can be used in the list of characters to escape, but you must quote the entire third argument of RewriteRule and the space must not be the last character in the list.

    # Escape spaces and question marks. The quotes around the final argument
    # are required when a space is included.
    RewriteRule "^search/(.*)$" "/search.php?term=$1" "[B= ?]"

    As it turns out, having multiple comma-separated flags seems to suffice for the space not being the last character with this configuration, and I was able to get it to work, which is only escaping the space before applying the rewrite:

    RewriteRule ^(.*)$ index.php?q=$1 "[B= ,L,QSA]"
    

    This solves the issue w/ autocomplete, and seems a lot less likely to cause collateral damage ;)

    There's also this newer directive: https://httpd.apache.org/docs/current/rewrite/flags.html#flag_bctls -- but it's only available in Apache 2.4.57 and later, and Debian Buster (still supported) is at 2.4.38

  • πŸ‡¦πŸ‡ΉAustria tgoeg

    I can't reproduce this anymore, seems to work with the stock .htaccess config in the composer package.
    It also has a different rewrite rule than the one mentioned above.

    See πŸ› Apache shows 403 forbidden when "destination=" contains url encoded question marks (%3F) (CVE-2024-38474) Closed: works as designed for details.

    If others can confirm that a current 10.2 or 10.3 also fixes this, we can close this issue.

Production build 0.71.5 2024