Skip to content

Commit 5165419

Browse files
committed
feature #4295 [Security] Hidden front controller for Nginx (phansys)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4295). Discussion ---------- [Security] Hidden front controller for Nginx For Nginx in PROD env, this makes more difficult to know that app is running Symfony. app.php is widely known as our default front controller. It is a small effort by security through obscurity. For Apache, [this 301 must be replaced by 404](https://github.com/symfony/symfony-standard/blob/77ee2a83c085169e0bd221510b5693dca504f682/web/.htaccess#L37). | Q | A | ------------- | --- | Doc fix? | no | New feature? | no | Applies to | 2.0+ | Tests pass? | yes | Fixed tickets | Commits ------- fed56c2 Updated docblock for config in DEV environment. d1f1b33 * Replaced IF statement by "internal" directive. * Splitted config for PROD and DEV environments. ebf4ea8 For Nginx in PROD env, this makes more difficult to know that app is running Symfony. app.php is widely known as our default front controller. It is a small effort by security through obscurity. For Apache, this 301 must be replaced by 404: https://github.com/symfony/symfony-standard/blob/77ee2a83c085169e0bd221510b5693dca504f682/web/.htaccess#L37
2 parents 42abc66 + fed56c2 commit 5165419

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cookbook/configuration/web_server_configuration.rst

+16-2
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,27 @@ are:
206206
# try to serve file directly, fallback to app.php
207207
try_files $uri /app.php$is_args$args;
208208
}
209-
210-
location ~ ^/(app|app_dev|config)\.php(/|$) {
209+
# DEV
210+
# Be sure to remove app_dev.php and config.php scripts when app is
211+
# deployed to PROD environment, this rule only must be placed on DEV
212+
location ~ ^/(app_dev|config)\.php(/|$) {
213+
fastcgi_pass unix:/var/run/php5-fpm.sock;
214+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
215+
include fastcgi_params;
216+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
217+
fastcgi_param HTTPS off;
218+
}
219+
# PROD
220+
location ~ ^/app\.php(/|$) {
211221
fastcgi_pass unix:/var/run/php5-fpm.sock;
212222
fastcgi_split_path_info ^(.+\.php)(/.*)$;
213223
include fastcgi_params;
214224
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
215225
fastcgi_param HTTPS off;
226+
# prevent explicit access and hide front controller
227+
# remove "internal" directive if you want to allow uri's like
228+
# http://domain.tld/app.php/some-path
229+
internal;
216230
}
217231
218232
error_log /var/log/nginx/project_error.log;

0 commit comments

Comments
 (0)