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

Sanitize and sandbox toot embeds #9552

Merged
merged 1 commit into from
Dec 23, 2018

Conversation

ClearlyClaire
Copy link
Contributor

Up until now, we blindly included oEmbed replies from remote toots in the embed modal.
Thankfully, since we introduced a Content Security Policy, this is not a security issue in Mastodon itself.

It however causes Content Security Policy warnings, and we may still provide users with malicious instructions.

The proposed change sanitizes the oEmbed content before suggesting it to the user, and also sandboxes the code to prevent executing scripts in a same-origin context.

This does cause some functionality loss: the generated code for embedding remote toots will not include the JS snippet needed to adjust the iframe's height.

@ClearlyClaire ClearlyClaire added the security Security issues and fixes, vulnerabilities label Dec 17, 2018
@ClearlyClaire
Copy link
Contributor Author

Another possibility, to avoid presenting the user untrusted code, is to accept serving remote toots with the embed controller, but it would require more changes.

@@ -10,6 +10,7 @@ def create
render json: status, serializer: OEmbedSerializer, width: 400
rescue ActiveRecord::RecordNotFound
oembed = FetchOEmbedService.new.call(params[:url])
oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED) if oembed[:html].present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break Mastodon embeds because they need a <script> for iframe resizing, and this ruleset strips out script tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said:

This does cause some functionality loss: the generated code for embedding remote toots will not include the JS snippet needed to adjust the iframe's height.

But I prefer that to instructing users to include untrusted code (note that embeds from your own instance don't go through that codepath and the javascript tag is still included).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is, it's okayish to instruct people to include scripts that we control, but I don't think it's ok at all to instruct them to include scripts from a remote instance we don't control.

@Gargron Gargron merged commit e25947d into mastodon:master Dec 23, 2018
@ClearlyClaire ClearlyClaire deleted the fixes/embed-sandbox branch March 14, 2019 15:42
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Security issues and fixes, vulnerabilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants