Repository navigation
Fix security vulnerabilities: HTTP Host Injection, XSS, path traversal - #1
Merged
Merged
Conversation
… traversal, and TypeError bug Co-authored-by: Sbgodin <3691603+Sbgodin@users.noreply.github.com>
Co-authored-by: Sbgodin <3691603+Sbgodin@users.noreply.github.com>
…nd escape hyphens in regex Co-authored-by: Sbgodin <3691603+Sbgodin@users.noreply.github.com>
Co-authored-by: Sbgodin <3691603+Sbgodin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify and address security vulnerabilities
Fix security vulnerabilities: HTTP Host Injection, XSS, path traversal
Feb 18, 2026
Sbgodin
marked this pull request as ready for review
May 27, 2026 08:42
There was a problem hiding this comment.
Pull request overview
This PR hardens HtmGem against several web security issues by validating request-derived inputs (host/style) and escaping user-controlled output in generated HTML, and adds regression tests plus a written security review summary.
Changes:
- Added
HTTP_HOSTvalidation inindex.phpto mitigate Host Header Injection. - Escaped multiple HTML outputs (code block alt text, CSS hrefs, menu links/labels) to address XSS vectors.
- Added a new PHPUnit security test suite and a
SECURITY_REVIEW.mdsummary.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
index.php |
Adds host header validation and style parameter whitelisting for CSS selection. |
lib-html.inc.php |
Escapes CSS hrefs and menu link/label output to prevent HTML/attribute injection. |
lib-htmgem.inc.php |
Escapes code-block alt text and fixes a header-title TypeError. |
tests/securityTest.php |
Adds regression tests for escaping and path traversal behavior. |
SECURITY_REVIEW.md |
Documents identified issues, fixes, and test results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+14
| // Sanitize HTTP_HOST to prevent Host Header Injection attacks | ||
| $domain = $_SERVER['HTTP_HOST']; | ||
| if (!preg_match('/^[a-zA-Z0-9.\-:]+$/', $domain)) { | ||
| http_response_code(400); | ||
| die("Invalid host header"); | ||
| } |
Comment on lines
+137
to
+141
| } else { | ||
| // Sanitize style parameter to prevent path traversal | ||
| if (preg_match('/^[a-zA-Z0-9_\-]+$/', $style)) { | ||
| $gt_html->addCss("$php_self_dir/css/$style.css"); | ||
| } |
Comment on lines
+42
to
+47
| **Example Attack**: | ||
| ```gemtext | ||
| ```<script>alert('XSS')</script> | ||
| malicious code | ||
| ``` | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security review identified 5 vulnerabilities and 1 bug. All remediated with input validation and output escaping.
Vulnerabilities Fixed
Critical: HTTP Host Header Injection
$_SERVER['HTTP_HOST']used without validation inindex.phpHigh: Cross-Site Scripting (4 instances)
lib-htmgem.inc.php:350)lib-html.inc.php:20)lib-html.inc.php:55-57)htmlspecialchars()withENT_QUOTESflag to all outputHigh: Path Traversal
preg_match('/^[a-zA-Z0-9_\-]+$/', $style)Bug Fix
TypeError in title processing
spacesCompress($linkText)called with undefined variablespacesCompress($title)in header casesTesting
Added 6 security tests covering XSS and path traversal scenarios. All 21 tests pass (15 existing + 6 new).
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh gh issue list --limit 20(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.