Follow-up to #1956698: Prevent access to YAML files using .htaccess and web.config
Problem/Motivation
#1956698: Prevent access to YAML files using .htaccess and web.config adds test coverage to ensure that yml files cannot be accessed through the browser. It would make sense to add similar coverage for the other extensions restricted by .htaccess.
Proposed resolution
One the parent issue is committed, add additional assertions to Drupal\system\Tests\System\HtaccessTest for the other restricted file types. It might be a good idea to make a test module that includes a dummy file of each file type and use those files for the test assertions, so that the test is not coupled to other specific files that might change in the future. (This would include converting the existing assertion for core/core.services.yml to use a test YAML file.)
Remaining tasks
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Novice | Instructions | |
| Add automated tests | Novice | Instructions | |
| Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Novice | Instructions |
User interface changes
None
API changes
None
Postponed until
#1956698: Prevent access to YAML files using .htaccess and web.config
Beta phase evaluation
| Issue category | Task because this is an enhancement. |
|---|---|
| Issue priority | Normal, because this is a test enhancement. |
| Unfrozen changes | Unfrozen because it only changes automated tests. |
| Disruption | Not disruptive for core/contributed and custom modules/themes because it is an automated test. |
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | interdiff.txt | 5.25 KB | eric115 |
| #39 | 2332029-39.patch | 4.37 KB | eric115 |
| #35 | interdiff.txt | 649 bytes | eric115 |
| #35 | 2332029-35.patch | 4.37 KB | eric115 |
| #27 | 2332029-27.patch | 4.37 KB | eric115 |
Comments
Comment #1
xjmComment #2
mpdonadioIs this also going to cover the .htaccess execution prevention rules in files, tmp, and private? If so, that should be added the the summary. If not, we should clarify the title a bit.
Comment #3
andyceo commented#1956698: Prevent access to YAML files using .htaccess and web.config is in, so unpostpone.
Comment #4
unstatu commentedBegun in Valencia Drupal Ladder 2014
Comment #5
pwolanin commentedComment #6
eric115 commentedI am happy to work on this.
Comment #7
eric115 commentedComment #8
eric115 commentedHere is a patch adding tests for the files in listed in the htaccess as being excluded. I have included two files, one of which has a modified htaccess to show that the test fails when the test is able to access those files.
Comment #11
eric115 commentedSorry, the patch files were missing some of the changes. These patch files have the new files created for testing access. Also changed the patch file names to follow convention better.
Comment #12
benjy commentedFor the bot
Comment #14
webchickThat was just the bot being thorough. ;)
Comment #15
eric115 commentedNot enough tests failed in test bot, this patch is just to check which tests did fail.
Comment #17
cilefen commentedThis should be
foreach (.Could you fix the parameter annotation in assertNoFileAccess(). It does not include the data type. I feel this is a justified change in this issue.
I like that you differentiate files that may start with a '.'. A poorly-configured web server may let those through. Are you sure all these file types usually begin with a '.'?
The code style is to put a comma here.
Comment #18
eric115 commentedThanks for your feedback, I have made those changes in this patch. In terms of the previous "fail" patch to prove these tests work, it looks like the test bot may have another htaccess file or other apache config that is still preventing access to most of the files (despite the modified htaccess file in the "fail" patch).
EDIT: Sorry please ignore this patch file, it has htaccess modifications in it. Please see comment #20
Comment #19
eric115 commentedComment #20
eric115 commentedSorry, this is the patch file without htaccess changes.
Comment #22
eric115 commentedModified the htaccess to allow access to the specified files to override the htaccess on the test bot website which was previously causing conflicts.
Comment #24
eric115 commentedThe test only covers files that are blocked by Drupal's htaccess that aren't temporary files (starting with a dot). I checked the default configuration on OS X, CentOs and Ubuntu and they all have IndexIgnore rules which block dot files by default.
Comment #25
eric115 commentedComment #26
eric115 commentedUpdated some comments to make more sense and made some other general improvements.
Comment #27
eric115 commentedModified a comment to have better wording.
Comment #28
benjy commentedEric has been working on this at DrupalSouth. Patch looks good and the tests add some great value. Nice work.
Comment #29
cilefen commented@Eric115 Cool! You should get in the habit of providing interdiffs when you make changes in new patches.
Comment #30
cilefen commented"access-tested" should be hyphenated.
Comment #31
cilefen commentedAdded the beta phase evaluation, which is needed to have issues committed right now.
Comment #32
benjy commentedReally?? Can you expand on that, I don't feel like they should be hyphenated when the nouns come first.
Comment #33
cilefen commented"Access-tested" is a compound forming two nouns into a verb. Those are hyphenated.
Comment #34
cilefen commentedLet's fix that comment please.
Comment #35
eric115 commentedHere is the patch with the hyphen in the comment. Also I have uploaded an interdiff.
Comment #36
benjy commentedLooks good.
Comment #37
sutharsan commentedComment #38
alexpottThese files belong in
core/modules/system/tests/fixtures/HtaccessTestsince the test is in system.Comment #39
eric115 commentedThanks you for the feedback so far everyone.
Here is a new patch file with the files moved to core/modules/system/tests/fixtures/HtaccessTest.
Comment #40
benjy commentedThe interdiff is missing the change to drupal_get_path() but the main patch looks good and addresses #38. Back to RTBC.
Comment #41
alexpottAdding test coverage is not blocked during beta. Committed 3874b0c and pushed to 8.0.x. Thanks!