Skip to content

[Router] Router does not correctly detect and reject env vars within parameters #32366

Closed
@bendavies

Description

@bendavies

Symfony version(s) affected: 3.2 - master

Description
Using env vars in routing configuration is not supported and actively denied:

#20687

if (preg_match('/^env\(\w+\)$/', $match[1])) {
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1]));
}

However, if we use indirection with a parameter we can avoid this error, but routing will not work as expected.

How to reproduce
This will be denied correctly, as described above:

# config.yaml
parameters:
    env(route_prefix): 'default'

# routes.yaml
some_route:
  path:       /%env(route_prefix)%/contact
  controller: App\Controller\MainController::contact

However, this will not throw an error:

# config.yaml
parameters:
    env(route_prefix): 'default'
    route_prefix: '%env(route_prefix)%'

# routes.yaml
some_route:
  path:       /%route_prefix%/contact
  controller: App\Controller\MainController::contact

This will allow the container to boot, but defining a different route_prefix env var will never have any effect.

Possible Solution
For good and non confusing DX, detect if parameters are pointing to env vars and deny building routes up front.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions