Skip to content

feat(security): allow data: URLs for images and videos.#8661

Merged
mprobst merged 1 commit intoangular:masterfrom
mprobst:data-image-urls
May 17, 2016
Merged

feat(security): allow data: URLs for images and videos.#8661
mprobst merged 1 commit intoangular:masterfrom
mprobst:data-image-urls

Conversation

@mprobst
Copy link
Copy Markdown
Contributor

@mprobst mprobst commented May 15, 2016

Allows known-to-be-safe media types in data URIs.

Part of #8511.

@mprobst mprobst added action: review The PR is still awaiting reviews from at least one requested reviewer area: security Issues related to built-in security features, such as HTML sanitation labels May 15, 2016
@mprobst
Copy link
Copy Markdown
Contributor Author

mprobst commented May 15, 2016

@rjamet

@mprobst mprobst mentioned this pull request May 15, 2016
17 tasks
@rjamet
Copy link
Copy Markdown
Contributor

rjamet commented May 16, 2016

LGTM. Maybe more tests for bad data: types, data:,something, other encodings ?

@mprobst
Copy link
Copy Markdown
Contributor Author

mprobst commented May 17, 2016

Good point, done.

Allows known-to-be-safe media types in data URIs.

Part of angular#8511.
@mprobst mprobst force-pushed the data-image-urls branch from 0f28d02 to dd50124 Compare May 17, 2016 08:57
@agpreynolds
Copy link
Copy Markdown
Contributor

Could we also add data:text/plain into the whitelist?

@mprobst
Copy link
Copy Markdown
Contributor Author

mprobst commented May 17, 2016

@agpreynolds what's the use case? I can't quite find a CSS property where plain text would be useful? If you want plain text as a background image, I think you'll need to use SVG or a style rule with a content property (where you can just bind text directly).

@agpreynolds
Copy link
Copy Markdown
Contributor

@mprobst The use case is as a link, such as for allowing users to download a file as a .txt e.g.

<a href="data:text/plain;charset=utf-8,{{encodeCsrFile()}}" download="{{certificate.reference}}.req">Download</a>

I had observed the same behaviour of the url being prepended with 'unsafe:' in RC1. Is it that this is a separate issue to the one you are fixing here?

@mprobst
Copy link
Copy Markdown
Contributor Author

mprobst commented May 17, 2016

@agpreynolds I'll defer to @koto and @rjamet, but it seems reasonable to me to require blessing a download with sanitizer.bypassSecurityTrustAsUrl. We're still working on the docs for this (sorry!), in a nutshell you inject DomSanitizationService into your controller, and then call sanitizer.bypassSecurityTrustAsUrl(myValue) to mark the value as "safe to use in a URL context".

@mprobst mprobst merged commit dd50124 into angular:master May 17, 2016
@mprobst mprobst added pr_state: LGTM and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 17, 2016
@rjamet
Copy link
Copy Markdown
Contributor

rjamet commented May 20, 2016

It's probably safeish, but there are some reasons to be unsure:

Since it's a really edge case, I'd keep it blacklisted, but mostly out of paranoia.

@mprobst mprobst deleted the data-image-urls branch May 20, 2016 14:22
@koto
Copy link
Copy Markdown
Contributor

koto commented May 20, 2016

data: uris are only supported since IE 8, and not for documents too, so text/plain upgrade to text/html wouldn't matter here.

Second point still stands. Data: uris are same origin (though some browsers break the spec - actually almost all of them break the spec) and they support scripting.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: security Issues related to built-in security features, such as HTML sanitation cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants