The backend doesn't prevent logged in users from reverting anyone's changes
Any logged in user is able to utilize the revert functionality, which is supposed to be limited to admins and librarians.
Relevant url?
Pick a work page that has more than one version.
Steps to Reproduce
- Go to an older version of a works page in Chrome (so that the URL has "v=..." in it)
- Open the Chrome developer tools and click on the Elements tab
- Edit an element at the top of the body as HTML (e.g.,
<span id="top"></span>) - Paste the following into the HTML (from here):
<div id="revertNotice">
<form name="revert" method="POST" action="$changequery(m='revert')">
<button type="submit">$_("Revert to this revision?")</button>
</form>
</div>
-
Replace the
actionvalue with the current URL + "&m=revert". E.g.:
-
Click outside the text box to save it
-
Click the revert button that shows up at the top of the screen

- Actual: The revert succeeds
- Expected: The revert fails
If done while logged out and you also include "&debug=true" in the action value, you get this error, which highlights the permissions check that doesn't work correctly:

Details
- Logged in (Y/N)? Y
- Browser type/version? Chrome
- Operating system?
- Environment (prod/dev/local)? prod
Proposal & Constraints
Fix the permissions check. I'm not in a position to check at the moment, but it seems like it should be something like:
if not user or not web.ctx.site.can_write(key) or not (user.is_admin() or user.is_librarian()):
Related files
The permission check is here: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/upstream/code.py#L218
Stakeholders
@mekarpeles @cdrini