Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow webviews to be set as trusted viewers#5592

Merged
jridgewell merged 5 commits into
ampproject:masterfrom
jridgewell:webview-ancestorOrigins-trusted-viewer
Oct 14, 2016
Merged

Allow webviews to be set as trusted viewers#5592
jridgewell merged 5 commits into
ampproject:masterfrom
jridgewell:webview-ancestorOrigins-trusted-viewer

Conversation

@jridgewell

Copy link
Copy Markdown
Contributor

Webviews can't set ancestorOrigins properly (maybe?), we can't use it to tell if we are in a trusted viewer context. Instead, fall back to our "old browser" path, which creates a trustedViewerResolver_. When the webview's integration script sets the message deliverer, it will resolve to the webview's passed origin.

Fixes #5563.

Webviews can't set `ancestorOrigins` properly (maybe?), we can't use it
to tell if we are in a trusted viewer context. Instead, fall back to our
"old browser" path, which creates a `trustedViewerResolver_`. When the
webview's integration script [sets the message
deliverer](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L947),
it [will
resolve](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L961-L962)
to the webview's passed origin.

Fixes ampproject#5563.

@cramforce cramforce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a test?

/**
* Whether the AMP document is embedded in a webview.
* @private @const {boolean}
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

!! to cast to boolean?

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.

Params are always strings. So, if webview == '0' that wouldn't work. Instead it should be this.params_['webview'] == '1' or such.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Not embedded in IFrame - can't trust the viewer.
trustedViewerResolved = false;
trustedViewerPromise = Promise.resolve(false);
} else if (this.win.location.ancestorOrigins) {

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.

Could we also check that the document is NOT currently iframed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a great case. I've added this to the #isWebviewEmbeded boolean, and added tests.

@jridgewell

Copy link
Copy Markdown
Contributor Author

Tons 'o tests.

@jridgewell jridgewell force-pushed the webview-ancestorOrigins-trusted-viewer branch from 7423847 to 479470f Compare October 14, 2016 16:41
@jridgewell jridgewell merged commit 8bd195c into ampproject:master Oct 14, 2016
@jridgewell jridgewell deleted the webview-ancestorOrigins-trusted-viewer branch October 14, 2016 18:00
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Allow webviews to be set as trusted viewers

Webviews can't set `ancestorOrigins` properly (maybe?), we can't use it
to tell if we are in a trusted viewer context. Instead, fall back to our
"old browser" path, which creates a `trustedViewerResolver_`. When the
webview's integration script [sets the message
deliverer](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L947),
it [will
resolve](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L961-L962)
to the webview's passed origin.

Fixes ampproject#5563.

* Add tests

* Do not trust "webviews" that are really bad actor iframes

We treat them like normal iframes.

* Test for '1' explicitly

* Fix test
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Allow webviews to be set as trusted viewers

Webviews can't set `ancestorOrigins` properly (maybe?), we can't use it
to tell if we are in a trusted viewer context. Instead, fall back to our
"old browser" path, which creates a `trustedViewerResolver_`. When the
webview's integration script [sets the message
deliverer](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L947),
it [will
resolve](https://github.com/ampproject/amphtml/blob/f28e116/src/service/viewer-impl.js#L961-L962)
to the webview's passed origin.

Fixes ampproject#5563.

* Add tests

* Do not trust "webviews" that are really bad actor iframes

We treat them like normal iframes.

* Test for '1' explicitly

* Fix test
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.

"Untrusted viewer url override" error emitted for every web view page load

3 participants