Suppose a site is http://www.a.com, and a simple page on the site can be http://www.a.com/node/1. A bot can inject a "index.php" when it is visiting the page, so the URL of the page it requested becomes http://www.a.com/index.php/node/1. The shipped .htaccess allows this URL, and forwards to Drupal, then Drupal will use http://www.a.com/index.php as its base URL for generating all the links on the site. This gets worse, when Drupal caches the links/menus generated by bots and displays them for normal users.
I originally thought this could be exploited to hurt SEO and "clean URL", and called it "uglify attack". But, after speaking with @alexpott in private, we conclude it is not a security problem. Therefore, opening up this issue.
Not only our shipped .htaccess has this problem. The default Nginx template for Drupal published on nginx.org https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/ also has the same problem. In fact, I tested a couple of sites hosted with Nginx and I was able to reproduce the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | htaccess_fix-3095854-30.patch | 1.3 KB | jblouvet |
| #29 | htaccess-fix.patch | 1.43 KB | jblouvet |
| #28 | htaccess-fix.patch | 1.43 KB | jblouvet |
| #21 | 3095854-20.patch | 1.43 KB | kapilv |
| #18 | 3095854-18.patch | 2.25 KB | skyredwang |
Comments
Comment #2
skyredwangUpdated my org attribution for this issue.
Comment #3
skyredwangComment #4
alexpottHere's a first pass. This copes with http://mysite.com/index.php/some/url -> http://mysite.com/some/url but it does not cope with http://mysite.com/index.php -> http://mysite.com/ which I think it needs to.
Comment #6
rishi.kulshreshthaI've tried to fixed the second issue in the attached patch. Now it also copes with http://mysite.com/index.php -> http://mysite.com/
Comment #7
rishi.kulshreshthaAttaching the new patch as the earlier one was missing the scaffold one.
Comment #10
rishi.kulshreshthaUpdated the
RewriteCond& theRewriteRuleas per the requirement.Comment #11
rishi.kulshreshthaComment #13
rishi.kulshreshthaFixed coding standards.
Comment #15
skyredwangLet's try this.
Comment #17
skyredwangApparently,
drupalGet()doesn't work with redirect, see #2794649: How to do a redirection test using simpletest?.Comment #18
skyredwangThis patch uses the solution mentioned in https://stackoverflow.com/a/24008632/1966269
Also, this problem is discussed in https://www.drupal.org/forum/support/post-installation/2016-09-19/how-to...
I don't think the automated test will pass, because of the reason mentioned in #17
Comment #19
kapilv commentedComment #21
kapilv commentedComment #22
kapilv commentedComment #25
deepak goyal commentedApplied patch #21 cleanly in drupal version (9.1.x).
Comment #28
jblouvet commentedIt seems that previous patches missed a `#` at the beginning of a line to correctly comment it.
Comment #29
jblouvet commentedAdding newlines for readability.
Comment #31
jblouvet commentedSorry for my previous patches. This one should be complete and apply correctly.
Comment #34
quietone commentedAdding a related issue.