2017 © Pedro Peláez
 

library protectedglobal

Protect against accidental use of superglobals.

image

phpgt/protectedglobal

Protect against accidental use of superglobals.

  • Monday, July 30, 2018
  • by g105b
  • Repository
  • 1 Watchers
  • 0 Stars
  • 31 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 48 % Grown

The README.md

Protect against accidental use of superglobals.

By default, PHP passes all sensitive user information around in superglobal variables, available for reading and modification in any code, including third party libraries. This directly violates a lot of the benefits of Object Oriented Programming, and can lead to unmaintainable code., (*1)

Assuming there are object oriented abstractions to the superglobals set up, this library can be used to replace all superglobals with objects that alert the developer of their protection and encapsulation, with an optional whitelist of superglobals to keep., (*2)


Build status Code quality Code coverage Current version PHP.Gt/ProtectedGlobal documentation , (*3)

There are two functions on the static Protection class:, (*4)

  1. removeGlobals - pass in an array containing the global arrays you wish to empty. Take an optional whitelist of keys to keep.
  2. overrideInternals - pass in all superglobal arrays to override with the ProtectedGlobal class.

Example usage:

// Before protecting, abstract the globals using an OOP mechanism of choice.
$input = new Input($_GET, $_POST, $_FILES);
// etc...

Protection::removeGlobals([$_ENV, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION], ["get" => ["xdebug"]]);
Protection::overrideInternals($_GLOBALS, $_ENV, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION);

// Now an exception will be thrown when trying to access a global variable:
$_SESSION["god-object"] = "Value I want to pass around globally";

The Versions

30/07 2018

dev-master

9999999-dev

Protect against accidental use of superglobals.

  Sources   Download

MIT

The Development Requires

15/01 2018

v0.0.1

0.0.1.0

Protect against accidental use of superglobals.

  Sources   Download

MIT

The Development Requires