¿Por qué la mayoría de los archivos PHP de Joomla! se inician con define(' JEXEC')...?

From Joomla! Documentation

This page is a translated version of the page Why do most of the Joomla! PHP files start with defined(' JEXEC')? and the translation is 0% complete.
Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎

La mayoría de los archivos PHP en Joomla! comienzan con la siguiente declaración:

Esta afirmación se comprueba si el archivo se llama desde dentro de una sesión Joomla! y protege tu sitio por lo que es más difícil para un cracker/hackers dañar tu sitio.

Why do most of the Joomla! PHP files start with defined(' JEXEC')?

Ayuda de dos formas principales:

1) Evita errores de funcionamiento de un archivo PHP que se espera se ejecute dentro de la rutina de carga de Jooma! y evita las vulnerabilidades de revelación de la ruta que surgen cuando se producen errores fatales de PHP.

defined('_JEXEC') or die('Restricted access');

2) También evita la inyección accidental de variables a través de un ataque a register globals impidiendo que el archivo PHP suponga que esta dentro de la aplicación cuando realmente no lo es.

Configurar los informes de errores tendría un efecto similar, sin embargo hay configuraciones en las que el cambio de configuración no están permitidos en PHP.INI. La verificación de JEXEC funciona independientemente de si la configuración se puede cambiar y no tiene otros efectos secundarios (por ejemplo, si estás depurando tener que reducir cada archivo al generar un informe de error sería molesto, porque tendrías que establecer un indicador de depuración para detenerlo o después de cada archivo se incluye restablecer el informe de error y eso ¡no es divertido!).


Sin embargo, esta línea NO debe ser incluida en el archivo principal index.php, ya que este es el programa que inicia la sesión en Joomla!.

When?

The check should be added to files that when accessed directly cause a path exposure. For example, the following error occurs when the Backlink System Plugin (/plugins/system/backlink.php file) has had the _JEXEC check disabled:

Fatal error: Call to undefined function jimport() in /Users/pasamio/Sites/workspace/joomla_15/plugins/system/backlink.php on line 18

As is evidenced, the 'jimport' function doesn't exist when the file is directly called so PHP raises an error and exposes the path to the file. Adding the defined or die check to this file will cause a "Restricted access" message to be displayed when the file is accessed.

So the general rule for the JEXEC check is if the PHP file depends on another file to operate properly. Typically if you access a file directly without the JEXEC check and a PHP error is raised (presuming your PHP error reporting is set to show errors by default) about a missing variable, function, object or similar then the file needs to be protected.

Some files don't need to be protected from this check. They might be files with no external dependencies (e.g. a simple class or bit of code) or they might be external files that can operate without being within Joomla!. Examples of this include TinyMCE's GZip'd Javascript generator which is entirely self contained.