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

ViewTransitions (v3.2.0+) unusable with a content security policy #8937

Closed
1 task
budparr opened this issue Oct 27, 2023 · 5 comments · Fixed by #8965
Closed
1 task

ViewTransitions (v3.2.0+) unusable with a content security policy #8937

budparr opened this issue Oct 27, 2023 · 5 comments · Fixed by #8965
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: view transitions Related to the View Transitions feature (scope)

Comments

@budparr
Copy link

budparr commented Oct 27, 2023

Astro Info

Astro                    v3.2.0
Node                     v20.6.1
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/tailwind

Also tested in v3.4.0

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The recent addition of a Route Announcer in <ViewTransitions /> in 3.2.0 appends a div with a style declaration. That inline style breaks content security policy without unsafe-inline so makes view transitions unusable with a CSP. While it's possible to declare unsafe-inline for styles in the CSP, that's not optimal from a security standpoint.

To reproduce, run Astro in example below, click on a new page and inspect. You'll find:

<div aria-live="assertive" aria-atomic="true" style="position:absolute;left:0;top:0;clip:rect(0 0 0 0);clip-path:inset(50%);overflow:hidden;white-space:nowrap;width:1px;height:1px">About Page</div>

Developers should have an option at least to render the styling in a stylesheet, or opt-out so they can implement on their own.

What's the expected result?

I think Announce should be optional—on by default with an option to not include—so that developers can implement in a manner appropriate for their needs.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-zxgdrp-6sx3md?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 27, 2023
@matthewp
Copy link
Contributor

Ah, ok yeah good call out. I think we can probably put this into the stylesheet we already have. I'll add it next week.

@matthewp matthewp added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Oct 27, 2023
@matthewp matthewp self-assigned this Oct 27, 2023
@matthewp matthewp added the feat: view transitions Related to the View Transitions feature (scope) label Oct 27, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Oct 27, 2023

Does this CSP directive help?

style-src-attr 'unsafe-hashes' 'sha256-scTtdlOdXHagPUz8jUu+nyUURgOE9FGWDkse4ziLZw4='

@budparr
Copy link
Author

budparr commented Oct 30, 2023

@lilnasy It's all relative. Any unsafe... directive is not optimal, though it could be okay on some sites. This came up for me on a site that I need to lock down pretty strictly (at least as much as I can do in an Astro context).

@martinburger
Copy link

Has this been fixed in Astro v4.2.1? I ask because I think I am encountering this problem.

Content-Security-Policy: The page’s settings blocked the loading of a resource at inline (“style-src”).

<style>.astro-route-announcer{position:absolute;left:0;top:0;clip:rect(0 0 0 0);clip-path:inset(50%);overflow:hidden;white-space:nowrap;width:1px;height:1px}@keyframes astroFadeInOut{0%{opacity:1}to{opacity:0}}@keyframes astroFadeIn{0%{opacity:0}}@keyframes astroFadeOut{to{opacity:0}}@keyframes astroSlideFromRight{0%{transform:translate(100%)}}@keyframes astroSlideFromLeft{0%{transform:translate(-100%)}}@keyframes astroSlideToRight{to{transform:translate(100%)}}@keyframes astroSlideToLeft{to{transform:translate(-100%)}}@media (prefers-reduced-motion){::view-transition-group(*),::view-transition-old(*),::view-transition-new(*){animation:none!important}[data-astro-transition-scope]{animation:none!important}}
[...]
	animation-name: astroFadeIn; }</style><style>[data-astro-transition-scope="astro-j5f6et4o-2"] { view-transition-name: astro-j5f6et4o-2; }@layer astro { ::view-transition-old(astro-j5f6et4o-2) {

@martinburger
Copy link

At least in v4.2.4, this has not been fixed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: view transitions Related to the View Transitions feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants