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

In 1.5.6, forced_allow_origin_value does not behave as documented and ignores allowed domains #138

Open
chrif opened this issue Nov 12, 2019 · 4 comments

Comments

@chrif
Copy link

chrif commented Nov 12, 2019

The response listener for forced_allow_origin_value is added before the call to checkOrigin. This results in the Access-Control-Allow-Origin header being added regardless of the allow_origin config, which is the opposite of the documented behavior:

Be aware that even if you set forced_allow_origin_value to *, if you also set allow_origin to http://example.com,
only this specific domain will be allowed to access your resources.

I need the latest version of Nelmio supporting Symfony 3. I tried to use dev-master as it seems fixed there, but it requires Symfony 4. Would a patch for Symfony 3 be possible?

In the meantime I'll just extend the listener and check origin there:

final class CorsListener extends \Nelmio\CorsBundle\EventListener\CorsListener {

	public function forceAccessControlAllowOriginHeader(FilterResponseEvent $event) {
		if (!$options = $this->configurationResolver->getOptions($request = $event->getRequest())) {
			return;
		}

		if (!$this->checkOrigin($request, $options)) {
			return;
		}

		$event->getResponse()->headers->set('Access-Control-Allow-Origin', $options['forced_allow_origin_value']);
	}

}

Thanks!

@Seldaek
Copy link
Member

Seldaek commented Nov 12, 2019

Just tagged 2.0 out of master, so yeah there is no way back there, but could do a 1.5.7 with the fix if you can figure out what the problem is. There weren't that many changes in between 1.5.6...master Sorry right now don't have time to investigate further.

@rvanlaak
Copy link

Would it be possible to enhance Symfony's Http Cache so it could work together with the allow_origin policy, so we do not need to set forced_allow_origin_value ?

@gndk
Copy link

gndk commented Jan 16, 2023

This is still broken, as the fix only applied to preflight requests.

@Seldaek
Copy link
Member

Seldaek commented Feb 15, 2023

I'm not sure here if this should be fixed or not #72 is the reason it is always set I believe - but maybe it isn't needed anymore now that we set Vary:Origin on response headers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants