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

Update trust levels for existing actions to spec #9954

Merged
merged 2 commits into from Jun 16, 2017

Conversation

dreamofabear
Copy link

@dreamofabear dreamofabear commented Jun 16, 2017

Fixes #9699.

Note that this will remove functionality by requiring high trust for some actions. Specifically, the actions:

  • AMP.goBack
  • <video>.play and <video>.unmute
  • <form>.submit

...can no longer be triggered by the following medium-trust events:

  • change (except from <select>)
  • slideChange
  • submit-success, submit-error
  • input-debounced

We don't have any low trust events yet, so actions that require low trust have no effective change.

See this spreadsheet for the canonical trust spec.

@dreamofabear
Copy link
Author

Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

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

LGTM

@cvializ
Copy link
Contributor

cvializ commented Jun 16, 2017

Do we have a way to know how many pages in the wild this might break?

@@ -351,7 +350,7 @@ export class AmpForm {
event.preventDefault();
}
// Submits caused by user input have high trust.
this.submit_(ActionTrust.MEDIUM); // TODO(choumx, #9699): HIGH.
this.submit_(ActionTrust.HIGH);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should unblock #9879 right? @cvializ

Copy link
Author

Choose a reason for hiding this comment

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

Yep. /cc @jridgewell

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should

</tr>
<tr>
<td>play</td>
<td>Plays the video.</td>
<td>High</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be High only if video is unmuted. Muted videos should be playable with Low, could you create an issue and assign to me?

Copy link
Author

Choose a reason for hiding this comment

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

👍 #9953

Copy link
Author

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

Do we have a way to know how many pages in the wild this might break?

We could use go/cookbook for this but I'm not sure it's necessary.

@@ -351,7 +350,7 @@ export class AmpForm {
event.preventDefault();
}
// Submits caused by user input have high trust.
this.submit_(ActionTrust.MEDIUM); // TODO(choumx, #9699): HIGH.
this.submit_(ActionTrust.HIGH);
Copy link
Author

Choose a reason for hiding this comment

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

Yep. /cc @jridgewell

</tr>
<tr>
<td>play</td>
<td>Plays the video.</td>
<td>High</td>
Copy link
Author

Choose a reason for hiding this comment

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

👍 #9953

this.action_.trigger(this.element, name, selectEvent,
ActionTrust.MEDIUM);
Copy link
Contributor

Choose a reason for hiding this comment

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

@choumx What does this mean for selector?

this.action_.trigger(this.element, name, selectEvent,
ActionTrust.MEDIUM);
ActionTrust.HIGH);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this not prevent slides from being in sync with selector via bind?

Copy link
Author

Choose a reason for hiding this comment

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

It wouldn't since high trust events can do everything that medium trust events can.

@dreamofabear dreamofabear merged commit 07977bd into ampproject:master Jun 16, 2017
@dreamofabear dreamofabear deleted the trust-levels-final branch June 16, 2017 21:00
@ericlindley-g
Copy link
Contributor

Just to double-check—was this taken through design review with these specific levels?

@dreamofabear
Copy link
Author

@ericlindley-g No, only in this PR with relevant parties.

Any concerns? It's a small PR so we can easily undo and review next week if you'd like.

@ericlindley-g
Copy link
Contributor

Thanks for the quick response, @choumx — non-urgent, so feel free to ignore until the week officially starts :)

I agree that the risk appears very low that we would break anyone in production with this (using medium-trust events to trigger these more disruptive actions in general would be strange). Would it make sense, process-wise, to run this through review next week, and only undo the merge if there are significant issues that come up?

As a side note: one reasonable implementation AMP may want to allow that would be restricted by this PR is playing or un-muting videos using checkboxes or radio buttons—though it's still a bit of an edge case. That's something we could either update the PR to allow now, or just think through it later on request, and see if it makes sense to open up. Would it be easy to make a targeted cookbook query just to make sure we're not breaking folks in production who might have already done these?

And is there validation in place that will also make pages that misuse these trust levels invalid, or does misuse just disable the interaction and a user-error is surfaced in the developer console?

@aghassemi
Copy link
Contributor

@choumx @ericlindley-g Ability to unmute based on checkbox seems important. I suggest we do a blanket rule that if event.isTrusted == true then trust is high. So change could be either medium or high depending on its trigger.

@ericlindley-g
Copy link
Contributor

@aghassemi What events fall in the category of "isTrusted == true"? I may not understand the significance of "isTrusted", but it seems like there would be events that the runtime trusts come from the user, but wouldn't want to trigger highly disruptive actions.

@MrSeanpull
Copy link

MrSeanpull commented Jun 28, 2017

I used it normally so far
Suddenly since yesterday
button click error

error.js:151 Trust for 'submit' (2) insufficient (min: 3).​​​

Ud	@	error.js:151
f.error	@	log.js:214
Hg.satisfiesTrust	@	action-impl.js:164
Ug	@	action-impl.js:502
f.trigger	@	action-impl.js:435
(anonymous)	@	action-impl.js:259
<form id="myform" class="p3 hide-inputs" method="post" action-xhr="/vote" target="_blank">
<label class="ampstart-btn vote">
<input type="radio" name="vote" value="up" on="change:myform.submit">GOOD 1</label>
<label class="ampstart-btn vote">
<input type="radio" name="vote" value="down" on="change:myform.submit">BAD 0</label>
</form>

http://imgur.com/tQNsOp9.jpg

@dreamofabear
Copy link
Author

@MrSeanpull Thanks for reporting this. Per our discussion in design review, we'll rollback this change and review a way forward in #10166.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants