sanitize/remove HTML elements if present in the data #1539
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.
As discussed in pelias/model#141 there is a possibility for HTML elements to be returned from the geoJSON API which could have a security impact for unaware clients.
For example, someone could edit OSM and set the name of a place to
Foo <script src="evil.js" /> Bar
and we would return that verbatim to the user.Security best-practises on the front-end could mitigate the threat but this could also catch unsuspecting users unaware.
This PR sanitizes/removes HTML elements if present in the data returned from elasticsearch.
There are two options for sanitising, namely 1. completely stripping the element (for
<SCRIPT>
etc) and 2. removing the elements but keeping the contents (for<P>
etc).I think in an ideal world we could implement this in the importers/model, that would also be cleaner since elasticsearch would never see the HTML in the first place.
However, it's much easier and much more secure to implement it in the
pelias/api
layer since we can guarantee that the JSON being returned does not contain HTML, whereas we'd have to trust the data indexed in elasticsearch to provide that guarantee if implemented in the importers.I'm open to either approach, this was just much simpler to implement.