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

Fix using helpers in content_security_policy and permissions_policy #45115

Merged
merged 1 commit into from May 18, 2022

Conversation

ghiculescu
Copy link
Member

@ghiculescu ghiculescu commented May 17, 2022

Fixes #45034

Currently helpers that are generated using helper_method cannot be used in content_security_policy and permissions_policy, this is because the use of yield causes self to be set incorrectly. By using instance_exec we ensure the scoping is correct so that you can access the same methods you'd be able to if you wrote your own before_action.

cc @lavaturtle

@guilleiguaran
Copy link
Member

Can we add a CHANGELOG entry for this?

Fixes rails#45034

Currently helpers that are generated using `helper_method` cannot be used in `content_security_policy` and `permissions_policy`, this is because the use of `yield` causes `self` to be set incorrectly. By using `instance_exec` we ensure the scoping is correct so that you can access the same methods you'd be able to if you wrote your own `before_action`.
@ghiculescu
Copy link
Member Author

@guilleiguaran done 👍

@ghiculescu
Copy link
Member Author

The red test seems unrelated. I think it's flakey.

image

@guilleiguaran guilleiguaran merged commit 6731fa8 into rails:main May 18, 2022
@ghiculescu ghiculescu deleted the csp-helpers branch May 18, 2022 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to use helpers within content_security_policy controller method
2 participants