Skip to content

Commit

Permalink
minor #47777 Guard scripts from being run in non-CLI contexts (nicola…
Browse files Browse the repository at this point in the history
…s-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

Guard scripts from being run in non-CLI contexts

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Although exposing those scripts on the web would be a mistake, let's disallow running them but from the CLI.

Commits
-------

edaea64 Guard scripts from being run in non-CLI contexts
  • Loading branch information
fabpot committed Oct 4, 2022
2 parents 25c0a20 + edaea64 commit 35910bf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Expand Up @@ -12,6 +12,10 @@
// Please update when phpunit needs to be reinstalled with fresh deps:
// Cache-Id: 2021-02-04 11:00 UTC

if ('cli' !== \PHP_SAPI && 'phpdbg' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

error_reporting(-1);

global $argv, $argc;
Expand Down
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

require dirname(__DIR__, 6).'/vendor/autoload.php';

use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTagsPassUtils;
Expand Down
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

$operators = ['not', '!', 'or', '||', '&&', 'and', '|', '^', '&', '==', '===', '!=', '!==', '<', '>', '>=', '<=', 'not in', 'in', '..', '+', '-', '~', '*', '/', '%', 'matches', '**'];
$operators = array_combine($operators, array_map('strlen', $operators));
arsort($operators);
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Intl/Resources/bin/common.php
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

define('LINE_WIDTH', 75);

define('LINE', str_repeat('-', LINE_WIDTH)."\n");
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Intl/Resources/bin/update-data.php
Expand Up @@ -23,6 +23,10 @@
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\Util\GitRepository;

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

require_once __DIR__.'/common.php';
require_once __DIR__.'/autoload.php';

Expand Down
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

// load new map
$data = file_get_contents('https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
$new = [];
Expand Down
Expand Up @@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

$usageInstructions = <<<END
Usage instructions
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/VarDumper/Resources/bin/var-dump-server
Expand Up @@ -10,6 +10,10 @@
* file that was distributed with this source code.
*/

if ('cli' !== PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}

/**
* Starts a dump server to collect and output dumps on a single place with multiple formats support.
*
Expand Down

0 comments on commit 35910bf

Please sign in to comment.