mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
XSS fixes from @mirko - see also 07dd358d0e (thanks @mirko, CVE-2026-127178)
This commit is contained in:
4 files changed
+64
-4
No files matched your search
@@ -254,6 +254,16 @@ class AliasHandler extends PFAHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
# A valid alias address contains exactly one "@": either "localpart@domain"
|
||||
# or a "@domain" catch-all. Reject anything else here - otherwise an address
|
||||
# such as "@domain@<payload>@domain" slips past the catch-all shortcut below
|
||||
# (explode() yields an empty local part, so check_email() is skipped) and is
|
||||
# stored verbatim, which allows stored HTML/JS injection in the alias list.
|
||||
if (substr_count($this->id, '@') !== 1) {
|
||||
$this->errormsg[$this->id_field] = Config::lang('pCreate_alias_address_text_error1');
|
||||
return false;
|
||||
}
|
||||
|
||||
list($local_part, $domain) = explode('@', $this->id);
|
||||
|
||||
# TODO: already checked in set() - does it make sense to check it here also? Only advantage: it's an early check
|
||||
|
||||
@@ -159,10 +159,10 @@
|
||||
<td>
|
||||
<form method="post" action="delete.php">
|
||||
<input type="hidden" name="table" value="mailbox">
|
||||
<input type="hidden" name="delete" value="{$item.username|escape:"quotes"}">
|
||||
<input type="hidden" name="delete" value="{$item.username}">
|
||||
{CSRF_Token}
|
||||
<button type="submit" class="btn btn-sm btn-danger list-action-icon" title="{$PALANG.del}" aria-label="{$PALANG.del}"
|
||||
onclick="return confirm ('{$PALANG.confirm}{$PALANG.mailboxes}: {$item.username}');">
|
||||
onclick="return confirm ('{$PALANG.confirm}{$PALANG.mailboxes}: {$RAW_tMailbox[$i].username|escape:'javascript'|escape:'html'}');">
|
||||
<span class="bi bi-trash" aria-hidden="true"></span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
+2
-2
@@ -201,11 +201,11 @@
|
||||
<td class="list-col-action">{if $item._can_delete}
|
||||
<form method="post" action="{#url_delete#}">
|
||||
<input type="hidden" name="table" value="{$table}">
|
||||
<input type="hidden" name="delete" value="{$RAW_item.$id_field|escape:"quotes"}">
|
||||
<input type="hidden" name="delete" value="{$item.$id_field}">
|
||||
{CSRF_Token}
|
||||
|
||||
<button class="btn btn-sm btn-danger list-action-icon" title="{$PALANG.del}" aria-label="{$PALANG.del}"
|
||||
onclick="return confirm('{$PALANG.{$msg.confirm_delete}|replace:'%s':$item.$id_field}')">
|
||||
onclick="return confirm('{$PALANG.{$msg.confirm_delete}|replace:'%s':{$RAW_item.$id_field|escape:'javascript'|escape:'html'}}')">
|
||||
<span class="bi bi-trash" aria-hidden="true"></span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@@ -308,6 +308,56 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An address with more than one "@" must be rejected. Before this was fixed,
|
||||
* a localpart such as '@example.com@<payload>' slipped past the catch-all
|
||||
* shortcut in validate_new_id() (empty local part => check_email() skipped)
|
||||
* and was stored verbatim, leading to stored HTML/JS injection in the alias
|
||||
* list (the id is rendered via $RAW_item in templates/list.tpl).
|
||||
*/
|
||||
public function testCannotCreateAliasWithMalformedAddress()
|
||||
{
|
||||
$this->addDomain('example.com', 'admin');
|
||||
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
'roles' => ['global-admin']
|
||||
]
|
||||
];
|
||||
|
||||
# the create-alias webform combines the 'localpart' and 'domain' fields via mergeId()
|
||||
$handler = new AliasHandler(1, 'admin', true);
|
||||
$handler->webformConfig(); # switch to webform (localpart + domain) mode
|
||||
|
||||
$address = $handler->mergeId([
|
||||
'localpart' => '@example.com@"><svg/onload=alert(1)>',
|
||||
'domain' => 'example.com',
|
||||
]);
|
||||
|
||||
$this->assertFalse($handler->init($address), "malformed address must be rejected: $address");
|
||||
$this->assertNotEmpty($handler->errormsg);
|
||||
|
||||
# nothing must have been stored
|
||||
$this->assertEmpty(db_query_all('SELECT address FROM alias WHERE address LIKE :a', ['a' => '%svg%']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression guard: the above fix must not break legitimate "@domain" catch-all aliases.
|
||||
*/
|
||||
public function testCatchallAliasStillAllowed()
|
||||
{
|
||||
$this->addDomain('example.com', 'admin');
|
||||
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
'roles' => ['global-admin']
|
||||
]
|
||||
];
|
||||
|
||||
$handler = new AliasHandler(1, 'admin', true);
|
||||
$this->assertTrue($handler->init('@example.com'), json_encode($handler->errormsg));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see https://github.com/postfixadmin/postfixadmin/pull/375 and https://github.com/postfixadmin/postfixadmin/issues/358
|
||||
|
||||
Reference in new issue
Block a user