Mask attachment HTML text nodes only, not href/src attributes - #9260
Open
c-tonneslan wants to merge 1 commit into
Open
Mask attachment HTML text nodes only, not href/src attributes#9260c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
apply_masks runs as plain text substitution, so a censor rule that matches part of a request's url_title was rewriting the iframe src and download link URLs in show_as_html. The downstream RecordNotFound when loading the PDF was actually the iframe fetching a no-longer-valid attachment URL. Walk the rendered HTML with Nokogiri and only mask text node content; attribute values like href and src stay untouched so the page chrome keeps working. Closes mysociety#9139 Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #9139.
apply_masksruns as plain-text substitution, so it was rewriting parts ofhrefandsrcvalues inside the rendered HTML when a censor rule matched a word in the request'surl_title. The actualRecordNotFound@FOIMonkey saw on the PDF viewer was the iframe fetching the censored attachment URL.Switched
show_as_htmlto walk the rendered HTML with Nokogiri and apply the masks only to text-node content; attribute values get left alone so the iframe and download link stay valid.The masking still happens for genuine text content (
@info_request.titlein the prefix partial, anything the text adapters extract from the document body), so the redaction story isn't changed for the user-facing parts.