Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

[Security][Proposal][WIP] Deny explicit requests to app.php/ #713

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions web/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

// This check prevents explicit access to front controller, except while Apache
// mod_rewrite fallback
// Feel free to remove this, extend it, or make something more sophisticated.
if (preg_match('#^/(.[^/]+)#', $_SERVER['REQUEST_URI'], $matches)
&& $_SERVER['SCRIPT_NAME'] === $matches[0]
) {
if (false === stripos($_SERVER['SERVER_SOFTWARE'], 'apache')
|| (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()))
) {
header('HTTP/1.0 404 Not found');
exit();
}
}

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

// Enable APC for autoloading to improve performance.
Expand Down