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

Disallow usage of style element and style attribute #279

Merged
merged 6 commits into from
Jul 6, 2023

Conversation

kevindew
Copy link
Member

@kevindew kevindew commented Jul 4, 2023

This forbids a user from inputting a style element as part of their
govspeak markdown or using the style attribute in their HTML.
Thus it prevents publishers from customising the style of a GOV.UK page.

I am very confident we never intended to let users do this and consider
this a bug fix - luckily, the evidence of usage is minimal. This bug
provides publishers with an unprecedented ability to re-style a GOV.UK
page in a way far outside of the GOV.UK brand guidelines.

The reason I'm confident this was not intended is because we went to
special effort to only style on table cell elements 7 years ago [1]. It
appears that when we adopted Sanitize::Config::Relaxed in 2012 [2],
style was not allowed as it was later added to Sanitize::Config::Relaxed
in 2014 [3].

The motivation for making this change is that, with the GOV.UK Content
Security Policy

style is blocked, so even if users could use this feature it wouldn't change
the frontend (but would generate reports).

I've been working through the apps to make sure publishers will only
have minimal effect from this change and know there's a couple of docs
in Whitehall that need fixing which will be co-ordinated with this gem release.

test/html_sanitizer_test.rb Outdated Show resolved Hide resolved
lib/govspeak/html_sanitizer.rb Show resolved Hide resolved
kevindew added 3 commits July 4, 2023 17:30
This forbids a user from inputting a style element as part of their
govspeak markdown or using the style attribute in their HTML.
Thus it prevents publishers from customising the style of a GOV.UK page.

I am very confident we never intended to let users do this and consider
this a bug fix - luckily, the evidence of usage is minimal. This bug
provides publishers with an unprecedented ability to re-style a GOV.UK
page in a way far outside of the GOV.UK brand guidelines.

The reason I'm confident this was not intended is because we went to
special effort to only style on table cell elements 7 years ago [1]. It
appears that when we adopted Sanitize::Config::Relaxed in 2012 [2],
style was not allowed as it was later added to Sanitize::Config::Relaxed
in 2014 [3].

[1]: b5b337e
[2]: c0fab20
[3]: rgrove/sanitize@86d53f9
I put the initial TODO comment as I was under the false impression that
these special rules could be removed once any hardcoded HTML was
removed. However these rules remain needed as they have to permit the
HTML that Kramdown generates, including style attributes for table cells.
These style attributes are then replaced in a post-processor method, but
they're still needed to be permitted at this point as sanitisation
happens before the post-processor.
There isn't any need to expand all attributes as these ones are allowed
implicitly.
@kevindew kevindew force-pushed the remove-style-from-allowlist branch from fdb5941 to 19a0d53 Compare July 4, 2023 16:30
kevindew added 3 commits July 5, 2023 10:15
I intend to extend this test to cover tables outside of those with
headers (admittedly I think this file is already testing beyond that).
These tests were mis-configured with the actual argument first before
the expected. Minitest convention is to have expected as the first
argument then the actual as the second one.
As suggested in the PR review for the changes we can simplify the use of
a transformer class to instead use sanitize config for it [1].

This does have a minor behavior difference that it will allow text-align
with invalid attributes, however since we replace style attributes on
table cells in post-processing this has no user consequence.

[1]: #279 (comment)
Copy link
Contributor

@ollietreend ollietreend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍🏻

@kevindew kevindew merged commit 37582a2 into main Jul 6, 2023
@kevindew kevindew deleted the remove-style-from-allowlist branch July 6, 2023 09:00
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.

2 participants