[Bug]: Port no longer showing in podcasts generated in 2.17.5 and newer #2467

Closed
opened 2026-04-25 00:07:28 +02:00 by adam · 9 comments
Owner

Originally created by @andrewinmoco on GitHub (Jan 8, 2025).

What happened?

After upgrading to the current audiobookshelf I'm unable play RSS feeds generated ion my podcast player. When investigating this I found that the port for the web server is no longer included in the generated RSS feed which means that the MP3 files can't be downloaded.

Working item from RSS feed generated in 2.17.4
image

Non working item from RSS feed generated in 2.17.5
image

What did you expect to happen?

I expect the port to be included in the URL to download the JPG and the MP3.

Steps to reproduce the issue

  1. Generate a RSS feed for a book while not on port 443
  2. Attempt to load the RSS feed in a podcast reader

Audiobookshelf version

v2.17.7

How are you running audiobookshelf?

Docker

What OS is your Audiobookshelf server hosted from?

Linux

If the issue is being seen in the UI, what browsers are you seeing the problem on?

None

Logs

No response

Additional Notes

No response

Originally created by @andrewinmoco on GitHub (Jan 8, 2025). ### What happened? After upgrading to the current audiobookshelf I'm unable play RSS feeds generated ion my podcast player. When investigating this I found that the port for the web server is no longer included in the generated RSS feed which means that the MP3 files can't be downloaded. Working item from RSS feed generated in 2.17.4 ![image](https://github.com/user-attachments/assets/c53edab9-7db1-4ef3-8b46-9fc3e555728b) Non working item from RSS feed generated in 2.17.5 ![image](https://github.com/user-attachments/assets/f71d52d9-3fd1-4c65-96e3-82d597b076e4) ### What did you expect to happen? I expect the port to be included in the URL to download the JPG and the MP3. ### Steps to reproduce the issue 1. Generate a RSS feed for a book while not on port 443 2. Attempt to load the RSS feed in a podcast reader ### Audiobookshelf version v2.17.7 ### How are you running audiobookshelf? Docker ### What OS is your Audiobookshelf server hosted from? Linux ### If the issue is being seen in the UI, what browsers are you seeing the problem on? None ### Logs _No response_ ### Additional Notes _No response_
adam added the bug label 2026-04-25 00:07:28 +02:00
adam closed this issue 2026-04-25 00:07:28 +02:00
Author
Owner

@advplyr commented on GitHub (Jan 8, 2025):

I see that this is a bug with express stripping the port. It doesn't strip the port number in all cases though so I haven't reproduced the issue.

https://expressjs.com/en/guide/migrating-5.html#req.host

In Express 4, the req.host function incorrectly stripped off the port number if it was present. In Express 5, the port number is maintained.

We can see about migrating to express 5 to resolve this.

Relevant PR https://github.com/advplyr/audiobookshelf/pull/3692 @mikiher

@advplyr commented on GitHub (Jan 8, 2025): I see that this is a bug with express stripping the port. It doesn't strip the port number in all cases though so I haven't reproduced the issue. https://expressjs.com/en/guide/migrating-5.html#req.host > In Express 4, the req.host function incorrectly stripped off the port number if it was present. In Express 5, the port number is maintained. We can see about migrating to express 5 to resolve this. Relevant PR https://github.com/advplyr/audiobookshelf/pull/3692 @mikiher
Author
Owner

@mikiher commented on GitHub (Jan 11, 2025):

I'll look at this. Maybe we can work around this. It would be also good switch to express 5.

@mikiher commented on GitHub (Jan 11, 2025): I'll look at this. Maybe we can work around this. It would be also good switch to express 5.
Author
Owner

@mikiher commented on GitHub (Jan 11, 2025):

Actually, looking at the code, it's not using req.host, but rather req.get('host'), (equivalent to req.headers.host) which should not suffer from the bug you referred to.

      const urlStartsWithRouterBasePath = req.url.startsWith(global.RouterBasePath)
      const host = req.get('host')
      const protocol = req.secure || req.get('x-forwarded-proto') === 'https' ? 'https' : 'http'
      const prefix = urlStartsWithRouterBasePath ? global.RouterBasePath : ''
      req.originalHostPrefix = `${protocol}://${host}${prefix}`

@andrewinmoco can you please do the following:

  • Copy the feed URL
  • Open a Chrome tab
  • Open Developer Tools (Ctrl+Shift+i or F12)
  • Click on the Network tab
  • Paste the feed URL in the address bar and press Enter
  • Find the request for the feed URL in the Network tab and click on it
  • Take a screenshot of the Request Headers section in the request's Headers tab and paste it here.
@mikiher commented on GitHub (Jan 11, 2025): Actually, looking at the code, it's not using `req.host`, but rather `req.get('host')`, (equivalent to `req.headers.host`) which should not suffer from the bug you referred to. ```js const urlStartsWithRouterBasePath = req.url.startsWith(global.RouterBasePath) const host = req.get('host') const protocol = req.secure || req.get('x-forwarded-proto') === 'https' ? 'https' : 'http' const prefix = urlStartsWithRouterBasePath ? global.RouterBasePath : '' req.originalHostPrefix = `${protocol}://${host}${prefix}` ``` @andrewinmoco can you please do the following: - Copy the feed URL - Open a Chrome tab - Open Developer Tools (Ctrl+Shift+i or F12) - Click on the Network tab - Paste the feed URL in the address bar and press Enter - Find the request for the feed URL in the Network tab and click on it - Take a screenshot of the `Request Headers` section in the request's `Headers` tab and paste it here.
Author
Owner

@andrewinmoco commented on GitHub (Jan 12, 2025):

@mikiher:

Before I share the screenshots I noticed something interesting:

I run audiobookshelf on docker (HTTP on port 13378). I use a nginx container on docker to expose audiobookshelf to the internet over TLS (on port 65033).

I use If I connect directly to the http server on the audiobookshelf container the port is properly shown in the RSS feed. If I connect to the TLS encrypred nginx container it isn't.

The headers are below:
Nginx (no port in RSS feed)
image

Directly to Audiobookshelf (port in RSS feed)
image

@andrewinmoco commented on GitHub (Jan 12, 2025): @mikiher: Before I share the screenshots I noticed something interesting: I run audiobookshelf on docker (HTTP on port 13378). I use a nginx container on docker to expose audiobookshelf to the internet over TLS (on port 65033). I use If I connect directly to the http server on the audiobookshelf container the port is properly shown in the RSS feed. If I connect to the TLS encrypred nginx container it isn't. The headers are below: Nginx (no port in RSS feed) ![image](https://github.com/user-attachments/assets/3286f184-1c9c-4665-942a-59e45d816d71) Directly to Audiobookshelf (port in RSS feed) ![image](https://github.com/user-attachments/assets/3f11d316-6ccd-44a5-8add-3d847be7c46e)
Author
Owner

@mikiher commented on GitHub (Jan 12, 2025):

Thanks for the response.

I suspect ngnix is stripping the port from the original request's Host header.
Can you please share your ngnix config file?
Specifically, I suspect you have the line:

proxy_set_header Host $host;

If so, can you try replacing it with

proxy_set_header Host $http_host;

and then restart ngnix and try again?

@mikiher commented on GitHub (Jan 12, 2025): Thanks for the response. I suspect ngnix is stripping the port from the original request's `Host` header. Can you please share your ngnix config file? Specifically, I suspect you have the line: ``` proxy_set_header Host $host; ``` If so, can you try replacing it with ``` proxy_set_header Host $http_host; ``` and then restart ngnix and try again?
Author
Owner

@andrewinmoco commented on GitHub (Jan 12, 2025):

@mikiher

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 $scheme; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_http_version 1.1;

You're 100% right, making that change in my common_location.conf fixed it.

Thank you for helping me solve what wasn't an audiobookshelf issue.

Not sure if I should close this or not, but from my point of view it's resolved and not a audiobookshelf bug.

@andrewinmoco commented on GitHub (Jan 12, 2025): @mikiher `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 $scheme; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_http_version 1.1; ` You're 100% right, making that change in my `common_location.conf` fixed it. Thank you for helping me solve what wasn't an audiobookshelf issue. Not sure if I should close this or not, but from my point of view it's resolved and not a audiobookshelf bug.
Author
Owner

@advplyr commented on GitHub (Jan 12, 2025):

Ah great, thanks for figuring that out. We can close this out

@advplyr commented on GitHub (Jan 12, 2025): Ah great, thanks for figuring that out. We can close this out
Author
Owner

@mikiher commented on GitHub (Jan 12, 2025):

This was actually useful.

We actually recommend using proxy_set_header Host $host for nginx configuration in our documentation. Usually it doesn't make a difference, since most people set their nginx on the default SSL port, in which case $host and $http_host are the same (since there's no port), but in your case they are different, since you don't use the default port.

@advplyr, I think we should probably change the nginx documentation to recommend proxy_set_header Host $http_host. Do you agree?

@mikiher commented on GitHub (Jan 12, 2025): This was actually useful. We actually recommend using `proxy_set_header Host $host` for nginx configuration in our documentation. Usually it doesn't make a difference, since most people set their nginx on the default SSL port, in which case $host and $http_host are the same (since there's no port), but in your case they are different, since you don't use the default port. @advplyr, I think we should probably change the nginx documentation to recommend `proxy_set_header Host $http_host`. Do you agree?
Author
Owner

@advplyr commented on GitHub (Jan 12, 2025):

Yeah that makes sense

@advplyr commented on GitHub (Jan 12, 2025): Yeah that makes sense
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#2467