Skip to content

Commit 377c79c

Browse files
committed
Mark parameter in ext/hash as sensitive
1 parent ff60f19 commit 377c79c

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

ext/hash/hash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
#include "ext/standard/php_var.h"
2727
#include "ext/spl/spl_exceptions.h"
2828

29-
#include "zend_interfaces.h"
29+
#include "zend_attributes.h"
3030
#include "zend_exceptions.h"
31+
#include "zend_interfaces.h"
3132
#include "zend_smart_str.h"
3233

3334
#include "hash_arginfo.h"

ext/hash/hash.stub.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ function hash(string $algo, string $data, bool $binary = false, array $options =
1414
/** @refcount 1 */
1515
function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string|false {}
1616

17-
/** @refcount 1 */
17+
/**
18+
* @sensitive-param $key
19+
* @refcount 1
20+
*/
1821
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string {}
1922

20-
/** @refcount 1 */
23+
/**
24+
* @sensitive-param $key
25+
* @refcount 1
26+
*/
2127
function hash_hmac_file(string $algo, string $filename, string $key, bool $binary = false): string|false {}
2228

23-
/** @refcount 1 */
29+
/**
30+
* @sensitive-param $key
31+
* @refcount 1
32+
*/
2433
function hash_init(string $algo, int $flags = 0, string $key = "", array $options = []): HashContext {}
2534

2635
function hash_update(HashContext $context, string $data): bool {}
@@ -49,12 +58,22 @@ function hash_algos(): array {}
4958
*/
5059
function hash_hmac_algos(): array {}
5160

52-
/** @refcount 1 */
61+
/**
62+
* @sensitive-param $password
63+
* @refcount 1
64+
*/
5365
function hash_pbkdf2(string $algo, string $password, string $salt, int $iterations, int $length = 0, bool $binary = false): string {}
5466

67+
/**
68+
* @sensitive-param $known_string
69+
* @sensitive-param $user_string
70+
*/
5571
function hash_equals(string $known_string, string $user_string): bool {}
5672

57-
/** @refcount 1 */
73+
/**
74+
* @sensitive-param $key
75+
* @refcount 1
76+
*/
5877
function hash_hkdf(string $algo, string $key, int $length = 0, string $info = "", string $salt = ""): string {}
5978

6079
#ifdef PHP_MHASH_BC

ext/hash/hash_arginfo.h

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test that sensitive parameters are marked sensitive.
3+
--FILE--
4+
<?php
5+
try {
6+
var_dump(hash_equals('foo', null));
7+
} catch (\Throwable $e) {
8+
echo $e, PHP_EOL;
9+
}
10+
try {
11+
var_dump(hash_hmac('foo', 'bar', 'baz'));
12+
} catch (\Throwable $e) {
13+
echo $e, PHP_EOL;
14+
}
15+
?>
16+
--EXPECTF--
17+
TypeError: hash_equals(): Argument #2 ($user_string) must be of type string, null given in %s:%d
18+
Stack trace:
19+
#0 %s(%d): hash_equals(Object(SensitiveParameterValue), Object(SensitiveParameterValue))
20+
#1 {main}
21+
ValueError: hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm in %s:%d
22+
Stack trace:
23+
#0 %s(%d): hash_hmac('foo', 'bar', Object(SensitiveParameterValue))
24+
#1 {main}

0 commit comments

Comments
 (0)