S3 uploads can be accessed by unauthenticated users. Rocketchat leaks bucket name and S3 access credentials
Description:
Uploaded files on s3 can be accessed without authentication even if the s3 bucket is secured correctly. Rocketchat also leaks the AWS AccessID. A URL copied from chat can result in a download of an attachment by an unauthorised user. The user also gains knowledge of the s3 Bucket name and AWS access credentials
Server Setup Information:
- Version of Rocket.Chat Server: 0.58.0
- Operating System: Ubuntu 16.04
- Deployment Method(snap/docker/tar/etc): tar
- Number of Running Instances: 1
- DB Replicaset Oplog: Enabled
- Node Version: 4.5.0
Steps to Reproduce:
-
Upload an image (or any other file) to Rocketchat with the S3 file storage backend
-
Right click the uploaded file in a channel and choose "copy image url" You'll get something like this : https://rocketchat.foo.com/file-upload/ABCDDEFGHIJLK/Screen%20Shot%202017-10-19%20at%2010.02.55.png
-
Copy the URL above into a browser without the RC cookies or use curl -I. Rocketchat will redirect via a 302 to https://
.s3.eu-west-2.amazonaws.com/ABCDEFGHIJ/uploads/GENERAL/ABCDEFGHIJABCDEFGHIJ?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ABCDEFGHIJABCDEFGHIJ%2F20171019%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20171019T134535Z&X-Amz-Expires=120&X-Amz-Signature=ABCDEFGHIJABCDEFGHIJABCDEFGHIJ&X-Amz-SignedHeaders=host
Expected behavior:
Rocketchat will ensure that a cookie is set for auth before doing the 302 Rocketchat will not leak the AWS Access Credentials
Actual behavior:
Rocketchat performs a 302 without authentication Rockethcat leaks the AWS Access Credentials
It turns out there's a setting under "File upload" called "Protect uploaded files". Setting this to true fixes the issue. I missed this setting, but upon looking through the sourcecode found it
The issue still remains that the URL that's 302'd by Rocketchat when this setting is disabled exposes a bit too much info (S3 bucket name and AccessID). If Rocketchat proxied connections rather than redirecting this exposure would be mitigated.
We now have proxy downloads. Also speaking to initial issue. Access creds not leaked. That’s signed access this is normal access procedure for s3
Maybe it's not exactly the same issue, but I think this is related. Let's say I upload an image with user A, with proxy enabled, and send it to user B using a private group. From what I tested, if a user C is aware of the file path (for example http://server/file-upload/maC8nhQCsryyYHgqB/images.jpeg) , he can access the file...
User C should get some kind of Denied authorization no ?
Make sure protected uploads is on

If you have access and send it... that might be allowing them access. I'm not 100% certain. One way to verify would be to pass it out of band to someone not in a room you upload it to and see if they can access it.