Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Restrict iframe embeds to an allowlist of approved providers (author scrubber + CSP frame-src) #480
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
base: main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Restrict iframe embeds to an allowlist of approved providers (author scrubber + CSP frame-src) #480
Changes from all commits
ba8981fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an operator configures a provider reached on a nondefault HTTPS port, such as
https://video.example:8443/embed/1, this check ignoresuri.portand allows the iframe, whilecsp_sourcesemits onlyhttps://video.example, which CSP matches on the scheme's default port. The browser therefore blocks an embed that the shared provider table reports as allowed; either support ports in provider entries and include them in the CSP source or reject nondefault ports during matching.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an approved host has another framable route, a source such as
https://www.youtube.com/embed/../watchpasses this raw-string prefix check, but browsers remove the dot segment and navigate to/watch. The CSP still permits the host, so this bypasses the provider's intended path-shape restriction; reject dot segments or canonicalize the URL path before applying the prefix check.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When authored content supplies a
styleattribute on an approved iframe, this override retains it verbatim and bypasses the CSS-value sanitization performed byPermitScrubber#scrub_attributes. Becausestyleis inPERMITTED_ATTRIBUTES, an author can inject declarations such as fixed positioning and a high z-index to turn the frame into a full-page overlay; filter the attribute names as intended, but still run the sanitizer's CSS scrubber on retained styles.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When any response builds this policy, Rails resolves the proc as one source expression rather than flattening its return value, so returning an array serializes a header like
frame-src ["https://youtube.com", ...]instead of space-separated origins. Browsers reject those bracketed/quoted expressions, causing every approved iframe to remain blocked; expand the dynamic list into individual CSP sources rather than returning an array from a single source proc.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This request neither crosses hosts nor tests a full absolute URL, so use
new_session_pathrather thannew_session_url. The rootAGENTS.mdspecifically requires_pathhelpers in controller and integration tests unless the host or full URL is under test.AGENTS.md reference: AGENTS.md:L8-L9
Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.