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

🐛 [amp-script] skip sha384 check for cross-origin scripts in sandboxed mode #36618

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions/amp-script/0.1/amp-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ export class AmpScript extends AMP.BaseElement {
return response.text();
} else {
// For cross-origin, verify hash of script itself (skip in
// development mode).
if (this.development_) {
// development and sandboxed mode).
if (this.development_ || this.sandboxed_) {
return response.text();
} else {
return response.text().then((text) => {
Expand Down
16 changes: 16 additions & 0 deletions extensions/amp-script/0.1/test/unit/test-amp-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ describes.fakeWin('AmpScript', {amp: {runtimeOn: false}}, (env) => {
expect(service.checkSha384).to.be.called;
});

it('should skip the check for sha384(author_js) for cross-origin src in sandboxed mode', async () => {
env.sandbox.stub(env.ampdoc, 'getUrl').returns('https://foo.example/');
element.setAttribute('src', 'https://bar.example/bar.js');
element.setAttribute('sandboxed', '');

stubFetch(
'https://bar.example/bar.js',
{'Content-Type': 'application/javascript; charset=UTF-8'},
'alert(1)'
);

await script.buildCallback();
await script.layoutCallback();
expect(service.checkSha384).not.to.be.called;
});

it('callFunction waits for initialization to complete before returning', async () => {
element.setAttribute('script', 'local-script');
script.workerDom_ = {callFunction: env.sandbox.spy()};
Expand Down