Luminova Framework

PHP Luminova: General Application Security Configurations

Last updated: 2026-11-28 20:57:12

Configure CORS, trusted origins and proxies, permissions, and error-message masking.

The Application Security Configuration class defines general security properties for Luminova applications. It controls file and directory permissions, CORS policy, trusted origins, hostnames and proxies, and which credential keys are masked in error output. These settings are used by Luminova\Http\Request, Luminova\Http\Header and other classes to validate incoming requests and secure application.


Class Definition

  • Full namespace: App\Config\Security
  • File path: /app/Config/Security.php
  • This configuration derives from Luminova\Base\AbstractConfig.
  • This class is final.

Properties

All properties are static and are accessed directly, for example Security::$allowOrigins.

dirPermissions

Unix permission used when creating a new directory.

public static int $dirPermissions = 0755;

The default 0755 lets the owner read, write and execute, while everyone else can only read and execute.


httpCorsPolicyMode

Defines where CORS security rules are enforced. The rules it controls are forbidEmptyOrigin, allowCredentials, allowOrigins and allowHeaders.

public static string $httpCorsPolicyMode = 'api';
ModeDescription
allEnforce CORS security on all HTTP requests.
webEnforce CORS security only on non API requests.
apiEnforce CORS security only on API requests, determined by env('app.api.prefix') or Router::isApiPrefix().
noneDisable CORS security validation.
Custom prefixA URI prefix such as users, to enforce CORS security only for that prefix.

Example:

// Apply CORS rules to every HTTP request
public static string $httpCorsPolicyMode = 'all';

forbidEmptyOrigin

When CORS validation rejects a request because its origin is missing, enabling this flag selects HTTP 400 for the rejection.

public static bool $forbidEmptyOrigin = false;

allowCredentials

Allow credentials for an accepted origin when the allow-origin value is specific. The response uses false for a wildcard origin.

public static bool $allowCredentials = true;

allowOrigins

Defines which request origins are permitted.

/**
 * @var string|string[]
 */
public static array|string $allowOrigins = '*';

Supported values:

ValueDescription
'*'Use a wildcard for matching origins. The CORS response sets allow-credentials to false.
'null'Allow requests with a null origin, such as local files or sandboxed documents.
'self'Allow the application hostname and its subdomains.
stringA single allowed origin.
arrayMultiple allowed origins.

Use a full origin such as https://api.example.com:8443 for an exact scheme, hostname, and port match. A leading-dot hostname such as .example.com matches that hostname and its subdomains. The self keyword matches the application hostname and its subdomains.

/**
 * @var string|string[]
 */
public static array|string $allowOrigins = [
    'https://example.com',          // Exact origin
    'https://api.example.com',      // Exact subdomain origin
    '.website.com',         // The domain and all subdomains
    'https://api.example.com:8443'  // Exact origin with a custom port
];

allowHeaders

Headers accepted in the Access-Control-Allow-Headers response. An empty array allows all headers.

/**
 * @var string[]
 */
public static array $allowHeaders = [];

Example:

/**
 * @var string[]
 */
public static array $allowHeaders = [
    'Content-Type',
    'Authorization',
    'X-Requested-With',
    'Host',
    'Accept',
    'User-Agent'
];

exposeHeaders

Response headers exposed to browser clients in cross origin requests. Browsers hide non standard response headers from JavaScript unless they are listed in Access-Control-Expose-Headers.

/**
 * @var string[]
 */
public static array $exposeHeaders = [];

Example:

/**
 * @var string[]
 */
public static array $exposeHeaders = [
    'X-Request-ID',
    'X-RateLimit-Remaining'
];

trustedOrigins

Trusted origin domains or patterns. Requests from these origins are considered safe.

/**
 * @var string[]
 */
public static array $trustedOrigins = [];

Used by Request::isTrusted() and Request::isTrustedOrigin().

Example:

/**
 * @var string[]
 */
public static array $trustedOrigins = [
    'https://example.com',
    '*.trusted.com'
];

trustedHostnames

Trusted hostnames or patterns. Requests from these hostnames are considered safe.

/**
 * @var string[]
 */
public static array $trustedHostnames = [];

Used by Request::isTrustedHost().

Example:

/**
 * @var string[]
 */
public static array $trustedHostnames = [
    'example.com',
    '*.trusted.net'
];

trustedProxies

Trusted proxy IP addresses and CIDR subnets.

/**
 * @var string[]
 */
public static array $trustedProxies = [];

Used by Request::isTrustedProxy() and Luminova\Http\Network\IP::isTrustedProxy().

Example:

/**
 * @var string[]
 */
public static array $trustedProxies = [
    '10.0.0.5',
    '192.168.0.0/16'
];

maskErrorMessageCredentials

Credential keys to mask in error messages and log output. Extend this list with your own sensitive field names.

/**
 * @var string[]
 */
public static array $maskErrorMessageCredentials = [ /* see below */ ];

The default list covers these groups:

GroupKeys
Authenticationpassword, passwd, pass, pwd, secret, credential, credentials, authorization, auth, auth_token
Tokens and API credentialstoken, access_token, refresh_token, id_token, api_key, apikey, client_id, client_secret
Cryptographic keysprivate_key, public_key, secret_key, signing_key, encryption_key, encryption_secret, signature
User and accountusername, email
Databasedatabase, db:database, dsn, connection_string, db_password, db_user, db_username
Session and requestcookie, set-cookie, session, session_id, csrf, csrf_token

Example:

/**
 * @var string[]
 */
public static array $maskErrorMessageCredentials = [
    'password', 'token', 'api_key',
    'card_number', 'ssn'
];

Replacing the array overrides the defaults, so keep any default keys you still want masked.