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

Enhancements for sanitizing URLs. #42

Merged
merged 1 commit into from
Sep 5, 2019
Merged

Conversation

BlakeStearman
Copy link
Member

Purpose

After some internal discussions, we identified a couple things that could be easily addressed to help developers using this library.

Issues addressed

The first issue identified was that as the img src attribute contains URLs like a href attributes, we should sanitize the URLs the same way we do for a href. This adds img src tag attribute to the built-in sanitization supporting our list of allowed protocols.

The second thing identified that we need to break out the URL sanitization into a public method to make it possible to sanitize URLs according to the rules, without necessarily needing to extend the whitelist and/or define custom filtering options to sanitize tag attributes containing URI values. This update adds a public sanitizeUrl method, which we then reuse in our custom filtering option that handles a href and img src parsing.

This update includes documentation and tests for the sanitizeUrl method as well as some cleanup to the tests for allowed protocols added in earlier enhancements.

Added `img` `src` tag attribute to the built-in sanitization as it is a publicly supported attribute and contains URI payloads; the same as what we do for `a` `href`.

Broke out the URL sanitization into a public method to make it possible to sanitize URLs according to the rules without necessarily needing to extend the whitelist and/or define custom filtering options to sanitize tag attributes containing URI values.
@BlakeStearman
Copy link
Member Author

cc @ffaubry @YukiDayDreamer

@ssylvia ssylvia merged commit b1b7d18 into master Sep 5, 2019
@ssylvia ssylvia deleted the BlakeStearman/enhancement branch September 5, 2019 17:49
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

Successfully merging this pull request may close these issues.

None yet

2 participants