Skip to content

Commit d8efd64

Browse files
Merge pull request #139 from julienloizelet/feat/folder-security-bis
feat(security): Protect geolocation and tls folders with .htaccess
2 parents f4aff8a + 6634c7e commit d8efd64

File tree

14 files changed

+51
-43
lines changed

14 files changed

+51
-43
lines changed

.cache/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!.gitignore
3+
!.htaccess

.distignore

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66
/tests
77
/vendor/crowdsec/bouncer/vendor
88
/vendor/crowdsec/bouncer/tools
9-
/vendor/crowdsec/bouncer/var
109
/vendor/crowdsec/bouncer/tests
1110
/vendor/crowdsec/bouncer/scripts
12-
/vendor/crowdsec/bouncer/examples
1311
/vendor/crowdsec/bouncer/docs
14-
/vendor/crowdsec/bouncer/docker
1512
/vendor/crowdsec/bouncer/README.md
1613
/vendor/crowdsec/bouncer/composer.json
1714
/vendor/crowdsec/bouncer/composer.lock
18-
/vendor/crowdsec/bouncer/phpunit.xml
19-
/vendor/crowdsec/bouncer/.phpdoc-md
20-
/vendor/crowdsec/bouncer/phpstan.neon
2115
/vendor/crowdsec/bouncer/.github
22-
/vendor/crowdsec/.bouncer-key
23-
.composer.json
24-
.composer.lock
2516
*.sh
2617
*.log
18+
*.mmdb
19+
*.pem
2720
composer.json
2821
composer.lock
2922
.distignore

.github/workflows/end-to-end-auto-prepend-test-suite.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ jobs:
5858
echo "WP_VERSION_CODE=$(echo wp${{ matrix.wp-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
5959
6060
- name: Create empty WordPress DDEV project (with Nginx)
61-
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }} --webserver-type=nginx-fpm
62-
63-
- name: Handle PHP version
64-
run: |
65-
sed -i -e 's/^php_version:.*/php_version: "${{ matrix.php-version }}"/g' .ddev/config.yaml
61+
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }} --php-version=${{ matrix.php-version }} --webserver-type=nginx-fpm
6662

6763
- name: Add Redis, Memcached, Crowdsec and Playwright
6864
run: |

.github/workflows/release-test.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ jobs:
6262
run: |
6363
echo "WP_VERSION_CODE=$(echo wp${{ matrix.wp-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
6464
65-
- name: Create empty WordPress DDEV project
66-
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }}
65+
- name: Create empty WordPress DDEV project (with Apache)
66+
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }} --php-version=${{ matrix.php-version }} --webserver-type=apache-fpm
6767

68-
- name: Handle PHP version
69-
run: |
70-
sed -i -e 's/^php_version:.*/php_version: "${{ matrix.php-version }}"/g' .ddev/config.yaml
7168

7269
- name: Add Redis, Memcached, Crowdsec and Playwright
7370
run: |

.gitignore

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,10 @@ vendor/crowdsec/bouncer/*
44
!vendor/crowdsec/bouncer/LICENSE
55

66

7-
# Systems
8-
.DS_Store
9-
107
#Tools
118
node_modules/
129
.test-results*
13-
tests/e2e/screenshots
14-
.cookies.json
15-
crowdsec-wp*
1610

1711
# App
18-
.bouncer-key
1912
*.log
20-
/.cache/*
21-
!/.cache/.htaccess
22-
/logs/*
23-
!/logs/.htaccess
24-
.vagrant
25-
.env
2613
inc/standalone-settings.php

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Security
1212

13-
- Add `.htaccess` to deny direct access of log and cache folders
13+
- Add `.htaccess` to deny direct access of plugin folders
1414

1515

1616
---

docs/USER_GUIDE.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,18 @@ Here are some examples of how to set options with the `WP-CLI` tool.
495495

496496
### Security
497497

498-
Logs and cache files generated by this plugin must be protected from direct access attempts.
498+
Some files used or created by this plugin must be protected from direct access attempts:
499499

500-
Logs files are created in the `wp-content/plugins/crowdses/logs` folder and cache files of the File system cache are
501-
created in the `wp-content/plugins/crowdses/.cache` folder.
500+
- Log files are created in the `wp-content/plugins/crowdsec/logs` folder
501+
- Cache files of the File system cache are created in the `wp-content/plugins/crowdsec/.cache` folder
502+
- TLS authentication files are located in the `wp-content/plugins/crowdsec/tls` folder
503+
- Geolocation database files are located in the `wp-content/plugins/crowdsec/geolocation` folder
502504

503505
**N.B.:**
504506
- There is no need to protect the `.cache` folder if you are using Redis or Memcached cache systems.
505507
- There is no need to protect the `logs` folder if you disable debug and prod logging.
508+
- There is no need to protect the `tls` folder if you use Bouncer API key authentication type.
509+
- There is no need to protect the `geolocation` folder if you don't use the geolocation feature.
506510

507511
#### Nginx
508512

@@ -515,8 +519,8 @@ server {
515519
...
516520
...
517521
...
518-
# Deny all attempts to acces log and cache folder of the crowdsec plugin
519-
location ~ /crowdsec/(.cache|logs) {
522+
# Deny all attempts to access some folders of the crowdsec plugin
523+
location ~ /crowdsec/(.cache|logs|tls|geolocation) {
520524
deny all;
521525
}
522526
...

geolocation/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
*.mmdb
1+
*
2+
!.gitignore
3+
!.htaccess

geolocation/.htaccess

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<IfVersion < 2.4>
2+
order allow,deny
3+
deny from all
4+
</IfVersion>
5+
<IfVersion >= 2.4>
6+
Require all denied
7+
</IfVersion>
8+

inc/admin/advanced-settings.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ function adminAdvancedSettings()
183183
}, ((Constants::CACHE_SYSTEM_PHPFS === get_option('crowdsec_cache_system')) ?
184184
'<input style="margin-right:10px" type="button" id="crowdsec_prune_cache" value="Prune now" class="button button-secondary" onclick="document.getElementById(\'crowdsec_action_prune_cache\').submit();">' : '').
185185
'<p>The File system cache is faster than calling Local API. Redis or Memcached is faster than the File System cache.<br>
186-
If you are using File system cache, please refer to <a target="_blank" href="https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#security">the documentation to deny direct access to the cache folder.</a></p>', [
186+
<b>Important note: </b> If you use the File system cache, make sure the <i>wp-content/plugins/crowdsec/.cache</i> path is not publicly accessible.<br>
187+
Please refer to <a target="_blank" href="https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#security">the documentation to deny direct access to this folder.</a></p>', [
187188
Constants::CACHE_SYSTEM_PHPFS => 'File system',
188189
Constants::CACHE_SYSTEM_REDIS => 'Redis',
189190
Constants::CACHE_SYSTEM_MEMCACHED => 'Memcached',
@@ -318,7 +319,9 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
318319
**************************/
319320

320321
add_settings_section('crowdsec_admin_advanced_geolocation', 'Geolocation', function () {
321-
echo 'Configure some details about geolocation.';
322+
echo 'Configure some details about geolocation.<br>
323+
<b>Important note: </b> If you use this feature, make sure the <i>wp-content/plugins/crowdsec/geolocation</i> path is not publicly accessible.<br>
324+
Please refer to <a target="_blank" href="https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#security">the documentation to deny direct access to this folder.</a>';
322325
}, 'crowdsec_advanced_settings');
323326

324327
// Field "Geolocation enabled"
@@ -372,7 +375,9 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
372375
******************************/
373376

374377
add_settings_section('crowdsec_admin_advanced_debug', 'Debug mode', function () {
375-
echo 'Configure the debug mode.<br>Please refer to <a target="_blank" href="https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#security">the documentation to deny direct access to the log folder.</a>';
378+
echo 'Configure the debug mode.<br>
379+
<b>Important note: </b> Make sure the <i>wp-content/plugins/crowdsec/logs</i> path is not publicly accessible.<br>
380+
Please refer to <a target="_blank" href="https://github.com/crowdsecurity/cs-wordpress-bouncer/blob/main/docs/USER_GUIDE.md#security">the documentation to deny direct access to this folder.</a>';
376381
}, 'crowdsec_advanced_settings');
377382

378383
// Field "crowdsec_debug_mode"

0 commit comments

Comments
 (0)