-
-
Notifications
You must be signed in to change notification settings - Fork 62
refactor(modulesadmin): replace $myts->htmlSpecialChars() with native… #1689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
043d7b7
075b5e6
b17dd2e
63e8ba9
a07d75d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -832,9 +832,7 @@ function xoops_module_update($dirname) | |||||||||||||||
| $dirname = trim((string) $dirname); | ||||||||||||||||
| $xoopsDB =& $GLOBALS['xoopsDB']; | ||||||||||||||||
|
|
||||||||||||||||
| $myts = \MyTextSanitizer::getInstance(); | ||||||||||||||||
|
|
||||||||||||||||
| $dirname = $myts->htmlSpecialChars(trim($dirname)); | ||||||||||||||||
| $dirname = htmlspecialchars(trim($dirname), ENT_QUOTES | ENT_HTML5, 'UTF-8'); | ||||||||||||||||
|
||||||||||||||||
| $dirname = htmlspecialchars(trim($dirname), ENT_QUOTES | ENT_HTML5, 'UTF-8'); | |
| $dirname = basename($dirname); | |
| if ('' === $dirname || !preg_match('/\A[a-zA-Z0-9_\-]+\z/', $dirname)) { | |
| trigger_error('Invalid module dirname: ' . basename($dirname), E_USER_WARNING); | |
| return ''; | |
| } |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In xoops_module_update(), $dirname is no longer HTML-escaped (the prior MyTextSanitizer call was removed), but it’s still interpolated into an HTML attribute for the module image URL. If a module dirname contains characters like quotes or <, this becomes an XSS risk in the admin UI. Keep $dirname unmodified for handler/path operations, but introduce a separately escaped/URL-encoded value when embedding it into HTML/URLs (and use that for the img src path segment).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,21 +215,18 @@ public function testSanitizesPostDataUsingFilterInput(): void | |
| } | ||
|
|
||
| /** | ||
| * Verify that MyTextSanitizer is used for HTML output sanitization. | ||
| * Verify that module dirnames and names are escaped for HTML output. | ||
| */ | ||
| public function testUsesTextSanitizerForOutput(): void | ||
| public function testUsesHtmlspecialcharsForOutput(): void | ||
| { | ||
| // Module dirnames and display names are identifier-like values that | ||
| // use native htmlspecialchars() with ENT_QUOTES | ENT_HTML5 instead | ||
| // of the MyTextSanitizer wrapper (which preserves & for free-form | ||
| // text — not needed for dirnames). | ||
| $this->assertStringContainsString( | ||
| '$myts = \MyTextSanitizer::getInstance();', | ||
| 'htmlspecialchars(', | ||
| $this->sourceCode, | ||
| 'Should initialize MyTextSanitizer' | ||
| ); | ||
|
|
||
| // Should use htmlSpecialChars for output | ||
| $this->assertStringContainsString( | ||
| '$myts->htmlSpecialChars', | ||
| $this->sourceCode, | ||
| 'Should use htmlSpecialChars for output sanitization' | ||
| 'Should use htmlspecialchars for output sanitization' | ||
| ); | ||
|
Comment on lines
225
to
241
|
||
| } | ||
|
Comment on lines
217
to
242
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$moduleis used as a module dirname forloadInfoAsVar()/getByDirname()and is also passed toxoops_confirm()(which already escapes hidden values). HTML-escaping it here can change the identifier (e.g.,&->&) and can also lead to double-escaped hidden fields. Prefer validating/normalizing the dirname (e.g.,basename()+ allowed-char regex or membership inXoopsLists::getModulesList()like the *_ok branches) and only escape when interpolating into HTML output.