🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.bugs.dist
3 messages
3 total messages Started by Andrew Bower Fri, 06 Nov 2026 00:00
Bug#1153131: shellinabox: directory traversal regression in --static-file handler (externalfile.c)
#3386
Author: Andrew Bower
Date: Fri, 06 Nov 2026 00:00
85 lines
5196 bytes
Control: tags -1 + pending upstream

Hi,

Thanks for the report!

On Thu, Nov 05, 2026 at 11:22:25PM +0200, Alexandru-Ionut Jipa wrote:
 
> shellinabox/externalfile.c's externalFileHttpHandler() (registered for
> the admin-opt-in --static-file <url-path>:<local-dir> command-line
> option) is supposed to block path traversal by rejecting any path
> component starting with ".". This is the guard added after the
> project's historical directory-traversal advisory, CVE-2012-4871. The
> guard loop has a pointer-advance bug that makes it ineffective for
> every path component after the first.

Sorry I didn't follow the reference to the prior CVE - seems to be for a
different package. However, the remainder of the report seems to stand.

> Root cause (externalfile.c):
[..]
>     // Any files/directories starting with a dot are inaccessible to us
>     do {
>         if (*ptr == '.') {
>             deleteURL(url);
>             free(fn);
>             httpSendReply(http, 404, "File not found", NO_MSG);
>             return HTTP_DONE;
>         }
>         ptr = strchr(ptr + 1, '/');
>     } while (ptr);
> }
> 
> strchr(ptr + 1, '/') returns a pointer AT the '/' character it finds,
> not past it. The loop then re-tests *ptr == '.', but ptr now points at
> '/', so the comparison is always false, and the loop repeats forever
> matching only slash characters. The only character of pathInfo ever
> actually checked against '.' is the very first one (before the loop
> starts). Every subsequent path-component boundary - including the
> character right after an internal '/' that would be '.' for a ".."
> component - is never inspected.
> 
> No URL-decoding happens anywhere before this handler runs, so literal
> ../ sequences in the raw HTTP request line work directly with no
> encoding needed.
> 
> Impact: any deployment using the documented --static-file option
> (serving custom CSS/branding assets - a supported, non-default
> feature) exposes an unauthenticated directory-traversal file-read
> primitive to any network client able to reach the HTTP(S) listener,
> reading arbitrary files readable by the shellinaboxd process user.
> This is a regression that reintroduces exactly the vulnerability class
> and feature area of CVE-2012-4871.

I agree, if an admin uses this feature they may expose filesystem
content outside the intended subtree.

I have reproduced this failure with the packaged version of this
application end to end (not with a contrived harness) and pushed my fix
to this as a patch in the 'salsa' packaging repository. The failure does
not reproduce with my fix:

https://salsa.debian.org/salvage-team/shellinabox/-/commit/e2f5383afd19e6a0199cbc8e71565b6cb97878a3

> Suggested fix, in externalfile.c:
> 
> do {
>     if (*ptr == '.') {
>         ...
>     }
>     ptr = strchr(ptr, '/');
>     if (ptr) { ptr++; }
> } while (ptr && *ptr);

Agreed this ought to work, too.

> No CVE has been requested yet for this - happy to coordinate on
> disclosure timing/CVE assignment.

I see no reason to delay a Debian upload for this as the bug is public,
reproduced and we have a fix. As you are keen to co-ordinate wider
activity, would you mind sending a report to the upstream project's
forge?

Andrew
Bug#1153131: shellinabox: directory traversal regression in --static-file handler (externalfile.c)
#3391
Author: Andrew Bower
Date: Fri, 06 Nov 2026 01:30
22 lines
3542 bytes
On Fri, Nov 06, 2026 at 03:17:01AM +0200, Alexandru-Ionut Jipa wrote:
> I rebuilt from the salsa tree at 5ab6bdf with both patches applied and
> re-ran the original request plus variants: /sfx/sub/../../secret-outside.txt,
> /sfx/sub//../../..., /sfx/sub/./../../..., /sfx/sub/%2e%2e/%2e%2e/... and
> /sfx/.hidden all return 404 now, while /sfx/marker.txt still returns 200.
> The strchrnul() + while (*ptr++) change looks right to me.
> 
> On the upstream forge: github.com/shellinabox/shellinabox has had no
> commits since January 2019 and its open issues from 2020 have no
> maintainer response, so I have nowhere useful to report this upstream.
> If you would still like a record there, I can open an issue pointing at
> #1153131 and your patch.

They are clearly not actively maintaining it but they did acceed to a
request to cut a tag corresponding to the 2.21 release recently (which
was until last year, untagged), so there is at least someone there and
other downstreams may pick it up!

The reason I suggest you post is that you have done all the research so
are probably best placed to but by all means mention that we have
applied a patch to bolster the case. Your patch may be more appropriate
upstream, although marginally larger, because it is not glibc-specific.
Bug#1153131: shellinabox: directory traversal regression in --static-file handler (externalfile.c)
#3654
Author: Andrew Bower
Date: Sat, 07 Nov 2026 11:40
45 lines
4133 bytes
Control: retitle -1 shellinabox: --static-file directory traversal guard ineffective

On Fri, Nov 06, 2026 at 03:37:38AM +0200, Alexandru-Ionut Jipa wrote:
> Done, both filed upstream:
> 
>   issue: https://github.com/shellinabox/shellinabox/issues/541
>   PR:    https://github.com/shellinabox/shellinabox/pull/540
> 
> The PR carries the strchr()-based variant (no glibc dependency), tested
> on an unmodified 4f0ecc3 build with the same request matrix as before;
> both reference #1153131 and your patch.

Excellent, thanks for that!

What makes you think this is a "regression", per the bug title? This
behaviour seems to have been present since this logic was first released
in this upstream commit:

commit aab20f5ed00104c8bc9d12d362085634ff64dead
Author: zodiac <zodiac@0da03de8-d603-11dd-86c2-0f8696b7b6f9>
Date:   Mon Dec 29 23:57:07 2008 +0000

    First public release of the version 2.0 rewrite. This is the
    first release of ShellInABox that supports an AJAX interface
    instead of the original Java applet.
    
    
    git-svn-id: https://shellinabox.googlecode.com/svn/trunk@2 0da03de8-d603-11dd-86c2-0f8696b7b6f9

I have suggested an alternative title but feel free to refine further it
you think it is inadequate.

I have come up with a simple reproducer that works from a bash prompt
in Linux using the packaged binary:

  mkdir /tmp/x
  unshare -rmn shellinaboxd -t -u 0 -g 0 --static-file /static:/tmp &
  nsenter -t $! -U -n --preserve-credentials
  ip link set up lo
  curl --path-as-is http://localhost:4200/static/x/../../etc/os-release
  exit
  kill %1

This will print the given file when the bug is present and return a 404
response when fixed.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads