Skip to content

Commit 3485dc2

Browse files
committed
Mark password_hash()'s password parameter as sensitive
1 parent ab8e416 commit 3485dc2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

ext/standard/password.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "php_rand.h"
2525
#include "php_crypt.h"
2626
#include "base64.h"
27+
#include "zend_attributes.h"
2728
#include "zend_interfaces.h"
2829
#include "info.h"
2930
#include "php_random.h"
@@ -448,6 +449,13 @@ PHP_MINIT_FUNCTION(password) /* {{{ */
448449
REGISTER_STRING_CONSTANT("PASSWORD_ARGON2_PROVIDER", "standard", CONST_CS | CONST_PERSISTENT);
449450
#endif
450451

452+
zend_add_parameter_attribute(
453+
zend_hash_str_find_ptr(CG(function_table), "password_hash", sizeof("password_hash") - 1),
454+
0,
455+
zend_ce_sensitive_parameter->name,
456+
0
457+
);
458+
451459
return SUCCESS;
452460
}
453461
/* }}} */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test that the password parameter is marked sensitive.
3+
--FILE--
4+
<?php
5+
try {
6+
var_dump(password_hash("foo"));
7+
} catch (\Throwable $e) {
8+
echo $e, PHP_EOL;
9+
}
10+
try {
11+
var_dump(password_hash("foo", "Invalid"));
12+
} catch (\Throwable $e) {
13+
echo $e, PHP_EOL;
14+
}
15+
?>
16+
--EXPECTF--
17+
ArgumentCountError: password_hash() expects at least 2 arguments, 1 given in %spassword_hash_sensitive_parameter.php:3
18+
Stack trace:
19+
#0 %spassword_hash_sensitive_parameter.php(3): password_hash(Object(SensitiveParameterValue))
20+
#1 {main}
21+
ValueError: password_hash(): Argument #2 ($algo) must be a valid password hashing algorithm in%spassword_hash_sensitive_parameter.php:8
22+
Stack trace:
23+
#0 %spassword_hash_sensitive_parameter.php(8): password_hash(Object(SensitiveParameterValue), 'Invalid')
24+
#1 {main}

0 commit comments

Comments
 (0)