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

Add base tag to html attachments view #5764

Merged
merged 1 commit into from
Aug 18, 2020

Conversation

karlbaker02
Copy link
Contributor

This PR adds a base tag to the html_attachments view. This view is used by the csv_preview controller and links currently rendered in the footer on this page currently point to the wrong URL (assets rather than GOV.UK); as a result, they return 404s. The footer itself is obtained through Slimmer, using the chromeless view that's part of Static where most URLs in the footer are relative.

By adding a base tag, all relative URLs on the page will be prefixed with the href attribute specified, which is the GOV.UK website root. The base tag can only appear in the head of a page, which is the reason for adding it into the partial frontend_base.

@karlbaker02 karlbaker02 force-pushed the add-base-tag-to-html-attachments-preview branch from d784b5f to d1ea6f0 Compare August 14, 2020 15:31
@kevindew
Copy link
Member

Super, this looks like a good approach. Nice one working this out. Have you tried it on integration? Might also be worth checking it works ok on draft stack, but I assume Plek is fine for that.

Implementation wise I'd suggest moving this from setting it on all html_publications (as the vast majority of them don't need it) and localising this to just csv_preview since that is the quirky bit of the stack. You could do that by setting @page_base_href in the controller and modifying your base tag accordingly which will cut html attachments out of the picture

@karlbaker02
Copy link
Contributor Author

Makes sense, thanks @kevindew. Haven't tested on integration yet as I'm waiting on the tests to pass before deploying the branch.

I wasn't sure how wide to scope this change originally, which is why I added it into local_assigns and only passed that in from the html_attachments view. I think your recommendation is the way forward, so I'll pick that up now.

@kevindew
Copy link
Member

cool cool - probably worth giving it a spin on integration as is anyway just to verify it does fix the problem

@karlbaker02 karlbaker02 force-pushed the add-base-tag-to-html-attachments-preview branch 4 times, most recently from 7a13849 to 5a36a48 Compare August 17, 2020 16:03
@karlbaker02 karlbaker02 requested a review from kevindew August 18, 2020 08:56
Copy link
Member

@kevindew kevindew 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, nice one Karl

@karlbaker02 karlbaker02 force-pushed the add-base-tag-to-html-attachments-preview branch from 5a36a48 to 84f246d Compare August 18, 2020 09:06
This commit fixes a long-standing bug with Whitehall, where links in the header and footer of the CSV preview page (rendered by the `CsvPreviewController`) contain relative links that point to the incorrect site root (`assets.publishing.service.gov.uk` rather than `www.gov.uk`), resulting in `404`s to any of those links which are followed. The footer itself is obtained through Slimmer, using the `chromeless` view that's part of `Static` where most URLs in the footer are set as relative.

The fix is achieved through adding a `base` tag to the `frontend_base` partial, which is set from the `CsvPreviewController` and rendered via the `html_attachments` view.

By adding a `base` tag, all relative URLs on the page will be prefixed with the `href` attribute specified, which is the GOV.UK website root. The `base` tag can only appear in the `head` of a page, which is the reason for adding it into the partial `frontend_base`.
@karlbaker02 karlbaker02 force-pushed the add-base-tag-to-html-attachments-preview branch from 84f246d to 5b96d9f Compare August 18, 2020 09:07
@karlbaker02 karlbaker02 merged commit 6028986 into master Aug 18, 2020
@karlbaker02 karlbaker02 deleted the add-base-tag-to-html-attachments-preview branch August 18, 2020 09:25
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 12, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 20, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 20, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 23, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 23, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 25, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
kevindew added a commit to alphagov/govuk_app_config that referenced this pull request Jan 26, 2023
A base element can be used to change the destination of relative paths,
this can be used as part of XSS to include a script file on a host an
attacker controls.

To prevent this we disable all uses of the base element as it is not
used on all GOV.UK views, bar one exception.

The exception is for CSV previews which are rendered by Whitehall [1] on
a different hostname (assets). As this is only for one app the
convention would be to modify the CSP in app. It is also unclear at this
point in time when or whether we will enable the CSP on Whitehall
frontend.

[1]: alphagov/whitehall#5764
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