Skip to content

✨ amp-script: allow 3p scripts without csp hash if sandboxed#33643

Merged
samouri merged 11 commits intoampproject:mainfrom
samouri:sandboxed-iframe
Apr 16, 2021
Merged

✨ amp-script: allow 3p scripts without csp hash if sandboxed#33643
samouri merged 11 commits intoampproject:mainfrom
samouri:sandboxed-iframe

Conversation

@samouri
Copy link
Copy Markdown
Member

@samouri samouri commented Apr 5, 2021

summary
Fixes: #30193. The relevant worker-dom changes are here: ampproject/worker-dom#1042.

  • Creates a new binary in dist.3p called amp-script-proxy-iframe.js
  • Creates the sandboxed attribute for <amp-script> and allows it in the validator. When present, csp is ignored.
  • 🍝 integration test

@samouri samouri changed the title amp-script: allow 3p scripts without csp hash if sandboxed ✨ amp-script: allow 3p scripts without csp hash if sandboxed Apr 6, 2021
@samouri samouri force-pushed the sandboxed-iframe branch 5 times, most recently from d71d334 to 447ccbc Compare April 9, 2021 21:47
@samouri samouri self-assigned this Apr 9, 2021
@samouri samouri requested a review from jridgewell April 14, 2021 22:32
@samouri samouri marked this pull request as ready for review April 14, 2021 22:32
@amp-owners-bot
Copy link
Copy Markdown

amp-owners-bot bot commented Apr 14, 2021

Hey @ampproject/wg-caching! These files were changed:

extensions/amp-script/validator-amp-script.protoascii

@samouri samouri requested a review from rsimha April 15, 2021 14:14
@samouri
Copy link
Copy Markdown
Member Author

samouri commented Apr 15, 2021

Added @rsimha to review build-system changes, and @jridgewell for reviewing the iframe + changes to amp-script.

Copy link
Copy Markdown
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

Build changes LGTM. 👍

onReceiveMessage: (data) => {
dev().info(TAG, 'From worker:', data);
},
sandbox: this.sandboxed_ && {iframeUrl},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What uses this?

Copy link
Copy Markdown
Member Author

@samouri samouri Apr 15, 2021

Choose a reason for hiding this comment

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

Nothing yet, its brand new.
Soon to be Permutive: #30193

);
const text = local.textContent;
if (this.development_) {
if (this.development_ || this.sandboxed_) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Setting sandboxed attribute will skip validation, but nothing handles the new sandboxed behavior. So, essentially, it lets you skip the validation only. Doesn't this need to wait, or do something so that we don't treat a sandboxed script as if it's just regular?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm confused. We don't treat it as regular. We pass worker-dom the sandboxed: {iframeUrl} configuration. This informs it to create a worker inside of an iframe instead of a Worker off the main window.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does that work currently?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes

@samouri
Copy link
Copy Markdown
Member Author

samouri commented Apr 15, 2021

@Gregable: when you get a chance (no rush) can you review the validator changes? Thanks!

@samouri samouri merged commit 89417c6 into ampproject:main Apr 16, 2021
@samouri samouri deleted the sandboxed-iframe branch April 16, 2021 15:09
rileyajones pushed a commit to rileyajones/amphtml that referenced this pull request Apr 16, 2021
…ect#33643)

* amp-script: allow scripts without csp hash if sandboxed

* It works

* Remove sha check

* Dist build working + Lint

* add integ test

* update validator

* greg feedback

* fix integ test url

* Add extra comment in html file

* use esm for esm builds

* lint
rochapablo pushed a commit to rochapablo/amphtml that referenced this pull request Aug 30, 2021
…ect#33643)

* amp-script: allow scripts without csp hash if sandboxed

* It works

* Remove sha check

* Dist build working + Lint

* add integ test

* update validator

* greg feedback

* fix integ test url

* Add extra comment in html file

* use esm for esm builds

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I2I: Run 3p service scripts in AMP

5 participants