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

Allow webviews to be set as trusted viewers #5592

Merged

Conversation

jridgewell
Copy link
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.
Copy link
Member

@cramforce cramforce left a comment

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}
*/
this.isWebviewEmbedded_ = this.params_['webview'];
Copy link
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -293,7 +299,7 @@ export class Viewer {
// Not embedded in IFrame - can't trust the viewer.
trustedViewerResolved = false;
trustedViewerPromise = Promise.resolve(false);
} else if (this.win.location.ancestorOrigins) {
} else if (this.win.location.ancestorOrigins && !this.isWebviewEmbedded_) {
Copy link
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
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
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