Skip to content

Pode does not report the correct Content-Length when serving a symlinked file #1597

@helpimnotdrowning

Description

@helpimnotdrowning

Describe the Bug

When a file is served with Set-PodeResponseAttachment or Add-PodeStaticRoute -DownloadOnly and the file is a symlink, the Content-Length is that of the symlink, not of the file itself. This causes issues when downloading such files in a browser, like the download hanging when the link size is bigger than the file (see bottom) or the file cutting off (in next section, download the file with Firefox instead of with netcat)

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a directory for this test script
  2. In here, save the following to server.ps1:
Import-Module Pode

Start-PodeServer {
	Add-PodeEndpoint -Address * -Port 8080 -Protocol HTTP
	
	Add-PodeStaticRouteGroup -FileBrowser -Routes {
		Add-PodeStaticRoute -Path '/' -Source . -DownloadOnly
	}
}
  1. Create a dummy file:
'a'*31 > file
  1. Create a symlink to it:
ln -s file link
  1. Now, ls the current directory. It should look something like the following. Note the size of file and link.
    Directory: .../lengthtest

UnixMode          User Group          LastWriteTime       Size Name
--------          ---- -----          -------------       ---- ----
-rw-r--r-- helpimnotd… helpimnotd… ****************         32 file
lrwxrwxrwx helpimnotd… helpimnotd… ****************          4 link -> file
-rw-r--r-- helpimnotd… helpimnotd… ****************        206 Server.ps1

  1. Now start the server.
  2. Use the following netcat commands to best see the discrepancy:
    file:
@"                             
GET /file HTTP/1.1
Host: localhost:8080

"@ | netcat localhost 8080

returns

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Disposition: attachment; filename=file
Content-Length: 32
Date: Mon, 25 Aug 2025 07:45:04 GMT
Server: Pode
X-Pode-ContextId: 8a492f9c-1d1c-1652-f0db-733e016f927e
Connection: close

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

This output is correct since the Content-Length is 32.

link:

@"                             
GET /link HTTP/1.1
Host: localhost:8080

"@ | netcat localhost 8080

returns

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Disposition: attachment; filename=link
Content-Length: 4
Date: Mon, 25 Aug 2025 07:46:10 GMT
Server: Pode
X-Pode-ContextId: dd23214a-19db-4c3f-8b1d-70cd124069a3
Connection: close

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Pode reports the Content-Length of the link to be 4, but supplies more than that.

Expected Behavior

Pode should correctly report the size of symlinked files

Platform

  • OS: Debian 13 Linux 6.12.38+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.38-1 (2025-07-16) x86_64 GNU/Linux
  • Browser: Firefox 141.0.3
  • Versions:
    • Pode: v2.12.1
    • PowerShell: 7.5.1

Additional Context

This does not happen when Add-PodeStaticRoute is not given the -DownloadOnly parameter.


To hang the download for the timeout period, replace the above steps 3, 4, and 5 with:
3. Create a dummy file:

'a' > file
  1. Create a symlink to it:
ln -s ./././././././././././././././././././././././file link
  1. Now, ls the current directory. It should look something like the following. Note the size of file and link.
    Directory: ~/Shirakami/lengthtest

UnixMode          User Group          LastWriteTime       Size Name
--------          ---- -----          -------------       ---- ----
-rw-r--r-- helpimnotd… helpimnotd… ****************          2 file
lrwxrwxrwx helpimnotd… helpimnotd… ****************         50 link -> ././././././
                                                               ././././././././././
                                                               ./././././././file
-rw-r--r-- helpimnotd… helpimnotd… ****************        206 Server.ps1

... and now download link with Firefox. After it finishes, open the file to see its contents:

a
HTTP/1.1 408 RequestTimeout
Content-Length: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions