Skip to content

SecurityBundle configuration via environment variables #28051

@zerkms

Description

@zerkms

Symfony version(s) affected: 4.1

Description

Security bundle configuration does not resolve environment variables (at least cookie_secure)

How to reproduce

framework:
    session:
        cookie_secure: '%env(bool:APP_SECURE)%'

This config looks good, whereas Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSessionDomainConstraintPass does not take it into account and uses $sessionOptions['cookie_secure'] as-is, which holds the env_b5fff47290c287c9_bool_APP_SECURE_93dabfcdbc8f9f7829f1a29cd3d2d083 value.

Possible Solution

Instead of YAML use the following ugly php-based configuration (or its variations)

<?php

$envSecure = getenv('APP_SECURE');
if ($envSecure === false) {
    $envSecure = true;
} else {
    $envSecure = filter_var($envSecure, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]);

    if ($envSecure === null) {
        $envSecure = true;
    }
}

$container->loadFromExtension('framework', [
    'session' => [
        'cookie_secure' => $envSecure,
    ],
]);

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help wantedIssues and PRs which are looking for volunteers to complete them.SecurityBundle

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy