Skip to content

Escape directory-listing output to prevent XSS - #9

Merged
Sandersm90 merged 1 commit into
masterfrom
fix/directory-listing-xss
Oct 1, 2026
Merged

Sandersm90 merged 1 commit into
masterfrom
fix/directory-listing-xss

Conversation

@Sandersm90

Copy link
Copy Markdown

Phase-1 finding F-1.2.

Server::showDirectoryListing() echoed the request URI and file names into HTML unescaped. With the opt-in directory-listing option on, a request URI like /"><script>…</script> is reflected verbatim → reflected XSS (and a crafted directory entry → stored XSS).

  • Extract a pure, testable Server::directoryListingHtml() that HTML-escapes the URI and file names (htmlspecialchars, ENT_QUOTES).
  • Harden glob() to ?: [] so a failed glob no longer passes false into usort()/array_map() (also clears two phpstan-baseline entries).
  • ServerTest coverage for escaping + normal links.

Full suite: 316 tests, phpstan green, php-cs-fixer clean.

Server::showDirectoryListing() echoed the request URI and file names into
HTML unescaped, allowing reflected XSS via the request URI (and stored XSS
via a crafted directory entry) when the opt-in directory-listing option is on.

- Extract a pure, testable Server::directoryListingHtml() that HTML-escapes
  the URI and file names (htmlspecialchars, ENT_QUOTES) before interpolation.
- Harden glob() to default to [] so a failed glob no longer feeds false into
  usort()/array_map() (also removes two phpstan-baseline entries).
- Add ServerTest coverage asserting URIs and file names are escaped.

Full suite: 316 tests, phpstan green, php-cs-fixer clean.
@Sandersm90
Sandersm90 merged commit 3d06669 into master Oct 1, 2026
5 checks passed
@Sandersm90
Sandersm90 deleted the fix/directory-listing-xss branch October 1, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant