Closed (fixed)
Project:
Drupal core
Version:
10.1.x-dev
Component:
base system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Dec 2022 at 12:20 UTC
Updated:
27 Oct 2023 at 23:18 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
eric_a commentedComment #3
eric_a commentedComment #4
eric_a commentedComment #6
eric_a commentedOops...
Comment #8
eric_a commentedLooks like the functionality for yarn.lock is in fact broken. Would be a bit embarrassing to enhance the .htaccess in 9.5.0 and 10.0.0 and having to then fix it immediately in 9.5.1 and 10.0.1, so escalating priority to major.
Comment #9
eric_a commentedI'm really not into regex, but the patch attached seems to improve the situation.
It seems the original patch displaced a $.
Comment #11
eric_a commentedRight, this is drupal/drupal, not drupal/core.
I had changed the scaffold htaccess, but forgot to change the root .htaccess.
Comment #12
eric_a commentedComment #13
longwaveThanks for spotting this and adding the test. I agree that the regex is malformed and the
$and|have accidentally been added the wrong way round.Comment #14
alexpottI think we need a few more tweaks to be consistent with the
^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$In fact I think really we should be putting both of these in that part of the rule for consistency... so it should be:
^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config|yarn\.lock|package\.json)$There are two more things that would be fixed by this... the dot would be escaped and therefore
packageAjsonwould not be matched. But also the path would have to be exactly yarn.lock or package.json.Comment #15
alexpottHere's the fix as per #14
Comment #16
xjmComment #17
xjmI thought it might be easier to review the total change to the file from before #3308369: Block access to yarn.lock and package.json, so this is what I did:
Committed the approaches from #11 and #15 to local branches from 10.1.x named "11" and 15".
Compared changes in the relevant files in those branches to
2233484^, which is the last commit before #3308369: Block access to yarn.lock and package.json, i.e.:.
Here's images of that to compare the two versions in color more easily:
#11
Scaffold file
.htaccess#15
Scaffold file
.htaccessComment #18
xjmOh and since I can, here's the "colorized interdiff" for #15.
I consider this RTBC. If someone else can review and +1, I am also willing to commit this once the tests finish (despite the code freeze) to fix a bad regression for 10.0.0.
Comment #19
effulgentsia commented#15 looks good to me. RTBC+1.
Comment #20
pandaski commentedDid a manual local test using Apache for testing htaccess.
The following are tested:
D10.0.x and D9.5.x
9.5.0-rc2 and 10.0.0-rc3
Before the patch:
both core/package.json and core/yarn.lock files are accessible with 200.
After the patch (via curl https://www.drupal.org/files/issues/2022-12-14/3327115-15.patch | git apply):
both core/package.json and core/yarn.lock files are 403 Forbidden
Comment #24
xjmThanks @pandaski for the manual test!
The test failure in https://www.drupal.org/pift-ci-job/2545386 is a known random that happens about once a week -- in fact it also just today happened in HEAD in https://www.drupal.org/pift-ci-job/2544788. So that is not blocking.
Committed to 10.1.x, and cherry-picked to 10.0.x and 9.5.x. Thanks!
I don't think this hotfix needs to be in the release notes; we can just use the release note @longwave added to the original issue.
Comment #25
xjmComment #26
eric_a commentedThanks!
Realizing just now that there's also web.config. That one looks much less broken. Maybe it needs just the escaping of the dots.
To be honest I didn't really look into that file. Which seems to be a common pattern for many. :-)
Comment #27
xjm@Eric_A I may also forget about it 50% of the time. Including when committing this issue. However, looking at its current code, I think it's OK:
If there's anything not-right about it, let's open a followup? Thanks!
Comment #28
effulgentsia commentedFWIW, I did check web.config before writing #19, and thought it was okay since it already included yarn.lock and package.json. However, I did miss that the dots weren't escaped there. I don't believe that's a security problem: it just means that web.config is denying access to file names (e.g.,
yarn-lock) that it doesn't have to deny access to. But a follow-up to make that consistent with what's in .htaccess is worth doing.Comment #30
o'briatThis should be send to nginx to update their page about drupal:https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/ (which is by the way an outdated doc).
Here's the fix for nginx:
If I understand it correctly apache match only the last part of the url/filepath (most right directory or filename) but nginx match the whole path.
So in order to deny all
composer.json,composer.lock,web.config,yarn.lockorpackage.json, I move this part to specific part of the regex:Could someone test and validate this modification?
As I don't understand what
Entries.*|Repository|Root|Tag|Templateis referring too, it would be nice to document this part.