Skip to content

Mask attachment HTML text nodes only, not href/src attributes - #9260

Open
c-tonneslan wants to merge 1 commit into
mysociety:developfrom
c-tonneslan:fix/dont-mask-attachment-html-attrs
Open

Mask attachment HTML text nodes only, not href/src attributes#9260
c-tonneslan wants to merge 1 commit into
mysociety:developfrom
c-tonneslan:fix/dont-mask-attachment-html-attrs

Conversation

@c-tonneslan

Copy link
Copy Markdown

Closes #9139.

apply_masks runs as plain-text substitution, so it was rewriting parts of href and src values inside the rendered HTML when a censor rule matched a word in the request's url_title. The actual RecordNotFound @FOIMonkey saw on the PDF viewer was the iframe fetching the censored attachment URL.

Switched show_as_html to 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.title in the prefix partial, anything the text adapters extract from the document body), so the redaction story isn't changed for the user-facing parts.

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>
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.

PDF viewer iframe fails with RecordNotFound when censor rule matches url_title

1 participant