RocketChat / RocketChat/Rocket.Chat

[Bug] Download path generation invalid in subdir behind nginx

Open
#20,984 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Description:

A valid upload file cannot be downloaded, because the download link provided differs from the actual upload link when Rocket.Chat runs in a subdir. Seems like RC is adding the already proxied subdir a second time for downloads.

Worked in pre 3.12 versions - started occuring with v3.12.0.

May be related to #20640, but can't figure out if the issue is the same or if there is just an invalid apache/nginx configuration in #20640.

Steps to reproduce:
  1. Install RC as docker with a subdir e.g. /chat
  2. Run RC behind a native nginx (config below)
  3. Upload a file
  4. Try to download the file
Expected behavior:

The file is downloaded successfully

Actual behavior:

A dummy file is created with a few kB instead.

Server Setup Information:
  • Version of Rocket.Chat Server: 3.12.0
  • Operating System: Ubuntu Server
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: wiredTiger
  • NodeJS Version: 12.18.4 - x64
  • MongoDB Version: 4.0.18
Client Setup Information
  • Desktop App or Browser Version: applies to both
  • Operating System: Windows/macOS/Linux
Additional context

Comparing upload and download links reveals the issue. A manual change of the download link (removing the invalid second /chat/ fixed it.

Upload Link:
https://<ROOT-URL>/chat/file-upload/8KAZmCZcswoEWQcZt/<FILENAME>.png

Download Link:
https://<ROOT-URL>/chat/chat/file-upload/8KAZmCZcswoEWQcZt/<FILENAME>.png?download

Relevant nginx conf:

	# rocket chat (docker)
	location ~* "^/[a-z0-9]{40}.(css|js)$" {
		root /opt/rocket/Rocket.Chat/programs/web.browser;
		access_log off;
		expires max;
	}

	location ~ ^/packages {
		root /opt/rocket/Rocket.Chat/programs/web.browser;
		access_log off;
	}

	location ~ ^/(avatar|images|sounds|assets|sockjs|fonts|theme|__meteor__) {
		rewrite ^ /chat$uri;
	}
	
	location /file-upload/ {
           proxy_pass http://127.0.0.1:3000/chat/file-upload/;
        }

	location /chat {
		autoindex on;
		proxy_pass http://127.0.0.1:3000/chat;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto https;
		proxy_set_header X-Nginx-Proxy true;
		proxy_redirect off;
		client_max_body_size 200M;
	}
Relevant logs:

None

Quick fix / Workaround:

I managed to get this fixed by an additional nginx.conf entry after location /file-upload/ {...}. However, this does not seem to be the preferred way to handle this?!

	# workaround invalid download path v3.12.0
	location /chat/chat/file-upload/ {
           proxy_pass http://127.0.0.1:3000/chat/file-upload/;
        }	

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the provided Docker, subdirectory, and nginx configuration, then compare the upload and download URLs shown in the report. Read the related discussion in #20640 and trace the download-path generation from that behavior. Done means downloads work behind nginx in a subdirectory without requiring the workaround location.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, nginx, typescript
Domain
backend, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.