dlcs / protagonist

MIT License
7 stars 2 forks source link

Auth1 cookie and AuthToken expiry can get out of sync #883

Closed donaldgray closed 1 week ago

donaldgray commented 4 months ago

Raised by Wellcome, there appears to be a bug where a user can end up with a cookie that references a UserSession that is expired in the database but the cookie expiry is being extended,. This means that if another clickthrough agreement is accepted the previous cookie is not removed and all images with clickthrough role return a 401.

Steps to replicate

  1. Open an item that requires clickthrough auth and accept agreement (note default TTL for role, default is 10mins)
  2. Confirm that you can view images that require clickthrough (e.g. open one in browser) - get 200 / view image.
  3. Note dlcs-token-{customer} cookie issued and note expiry.
  4. Note expiry of corresponding AuthToken in database.
  5. Wait more than TTL and request clickthrough image again (images that require auth have a cache-control:private header sent so try a different size/rotation/quality/format to ensure it's fresh) and confirm response is 401.
  6. The dlcs-token-{customer} cookie will still be present with extended expiry.
  7. AuthToken in database expiry is in past and doesn't update.

Example links for Wellcome where this was noticed (see slack for more details)

Thoughts:

JackLewis-digirati commented 1 week ago

This issue has now been fixed with #916

The issue for this was that cloudfront was caching authentication requests for cookies due to the authentication request looking like the same request every time (specifically the action token response here). This caused the caller to think that the dlcs-token-* cookie was extended, when in reality there had been no extension. This tricked applications (like the Wellcome works page) into requesting images that were forbidden due to an expired token

In order to fix this, no-store headers were added to authentication endpoints meaning that cloudfront no longer caches them.