openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

The backend doesn't prevent logged in users from reverting anyone's changes

Open SouthGoingZax opened this issue 6 years ago • 0 comments

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

  1. Go to an older version of a works page in Chrome (so that the URL has "v=..." in it)
  2. Open the Chrome developer tools and click on the Elements tab
  3. Edit an element at the top of the body as HTML (e.g., <span id="top"></span>)
  4. 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>
  1. Replace the action value with the current URL + "&m=revert". E.g.: Screen Shot 2020-11-12 at 8 26 17 PM

  2. Click outside the text box to save it

  3. Click the revert button that shows up at the top of the screen Screen Shot 2020-11-12 at 8 27 37 PM

  • 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: Screen Shot 2020-11-12 at 8 05 19 PM

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

SouthGoingZax avatar Nov 13 '20 04:11 SouthGoingZax