Protect static photo URLs with signing #51
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: nonshy/website#51
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, the actual file names of the .jpg images under /static/photos are not authenticated: if you get the direct link to one, you can always grab it even if not logged in. The site mainly relies on photo filenames to be randomized and unguessable.
With NGINX ngx_http_auth_request we may be able to protect these files and validate them against a logged-in user.
How it works
On the NGINX side, you configure the /static/ folder to do a subrequest for authentication:
On the nonshy website side: have a handler endpoint on /v1/auth/static.
Interesting findings:
Implementation
The JWT token's claims include:
In the vast majority of on-website use cases (gallery, forums, profiles, etc.) - the signed JWT tokens are for the current user only, are tied to the photo's file name quite well, and expire after 30 seconds.
There were a couple of interesting edge cases:
Signatures generated for those images are marked as for "Anyone" and they expire in 7 days rather than 30 seconds (to account for users who lurk in the chat room for days at a time).
Note: if your profile picture is friends-only or private, both the chat room AND your "limited logged-out view" instead show the placeholder yellow/pink avatars, so users with private pics will never have such a long-lived JWT token generated for theirs. Only square cropped avatars are ever given these signatures.