Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support https proxy #1096

Open
hvanoch opened this issue Mar 3, 2023 · 0 comments
Open

Support https proxy #1096

hvanoch opened this issue Mar 3, 2023 · 0 comments

Comments

@hvanoch
Copy link

hvanoch commented Mar 3, 2023

We are experiencing the same issue as described here: #1025
We did found the cause and solution.

This happens when proxing an https for a http request.
In


The thirth parameter is not configured. If you provide the request_stack service it will actually check if https is used with the symfony request, instead of the PHP $_SERVER variable. The symfony request has checks that validate if the request is being used by a proxy.
So changing it from:

    oro_security.csrf_token_manager:
        class: Symfony\Component\Security\Csrf\CsrfTokenManager
        public: false
        arguments:
            - '@security.csrf.token_generator'
            - '@oro_security.csrf.cookie_token_storage'

to

    oro_security.csrf_token_manager:
        class: Symfony\Component\Security\Csrf\CsrfTokenManager
        public: false
        arguments:
            - '@security.csrf.token_generator'
            - '@oro_security.csrf.cookie_token_storage'
            - '@request_stack'

Fixes the issue.

The symfony class that is used looks like.

    public function __construct(TokenGeneratorInterface $generator = null, TokenStorageInterface $storage = null, $namespace = null)
    {
        $this->generator = $generator ?? new UriSafeTokenGenerator();
        $this->storage = $storage ?? new NativeSessionTokenStorage();

        $superGlobalNamespaceGenerator = function () {
            return !empty($_SERVER['HTTPS']) && 'off' !== strtolower($_SERVER['HTTPS']) ? 'https-' : '';
        };

        if (null === $namespace) {
            $this->namespace = $superGlobalNamespaceGenerator;
        } elseif ($namespace instanceof RequestStack) {
            $this->namespace = function () use ($namespace, $superGlobalNamespaceGenerator) {
                if ($request = $namespace->getMainRequest()) {
                    return $request->isSecure() ? 'https-' : '';
                }

                return $superGlobalNamespaceGenerator();
            };
        } elseif (\is_callable($namespace) || \is_string($namespace)) {
            $this->namespace = $namespace;
        } else {
            throw new InvalidArgumentException(sprintf('$namespace must be a string, a callable returning a string, null or an instance of "RequestStack". "%s" given.', get_debug_type($namespace)));
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant