Skip to content

Mark parameters in bundled extensions as sensitive #8352

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

Merged
merged 12 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/ftp/ftp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function ftp_connect(string $hostname, int $port = 21, int $timeout = 90): FTP\C
function ftp_ssl_connect(string $hostname, int $port = 21, int $timeout = 90): FTP\Connection|false {}
#endif

/** @sensitive-param $password */
function ftp_login(FTP\Connection $ftp, string $username, string $password): bool {}
function ftp_pwd(FTP\Connection $ftp): string|false {}
function ftp_cdup(FTP\Connection $ftp): bool {}
Expand Down
4 changes: 3 additions & 1 deletion ext/ftp/ftp_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/ftp/php_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "ext/standard/info.h"
#include "ext/standard/file.h"
#include "Zend/zend_attributes.h"
#include "Zend/zend_exceptions.h"

#include "php_ftp.h"
Expand Down
3 changes: 2 additions & 1 deletion ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
#include "ext/standard/php_var.h"
#include "ext/spl/spl_exceptions.h"

#include "zend_interfaces.h"
#include "zend_attributes.h"
#include "zend_exceptions.h"
#include "zend_interfaces.h"
#include "zend_smart_str.h"

#include "hash_arginfo.h"
Expand Down
29 changes: 24 additions & 5 deletions ext/hash/hash.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ function hash(string $algo, string $data, bool $binary = false, array $options =
/** @refcount 1 */
function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string|false {}

/** @refcount 1 */
/**
* @sensitive-param $key
* @refcount 1
*/
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string {}

/** @refcount 1 */
/**
* @sensitive-param $key
* @refcount 1
*/
function hash_hmac_file(string $algo, string $filename, string $key, bool $binary = false): string|false {}

/** @refcount 1 */
/**
* @sensitive-param $key
* @refcount 1
*/
function hash_init(string $algo, int $flags = 0, string $key = "", array $options = []): HashContext {}

function hash_update(HashContext $context, string $data): bool {}
Expand Down Expand Up @@ -49,12 +58,22 @@ function hash_algos(): array {}
*/
function hash_hmac_algos(): array {}

/** @refcount 1 */
/**
* @sensitive-param $password
* @refcount 1
*/
function hash_pbkdf2(string $algo, string $password, string $salt, int $iterations, int $length = 0, bool $binary = false): string {}

/**
* @sensitive-param $known_string
* @sensitive-param $user_string
*/
function hash_equals(string $known_string, string $user_string): bool {}

/** @refcount 1 */
/**
* @sensitive-param $key
* @refcount 1
*/
function hash_hkdf(string $algo, string $key, int $length = 0, string $info = "", string $salt = ""): string {}

#ifdef PHP_MHASH_BC
Expand Down
10 changes: 9 additions & 1 deletion ext/hash/hash_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions ext/hash/tests/sensitive_parameter.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test that sensitive parameters are marked sensitive.
--FILE--
<?php
try {
var_dump(hash_equals('foo', null));
} catch (\Throwable $e) {
echo $e, PHP_EOL;
}
try {
var_dump(hash_hmac('foo', 'bar', 'baz'));
} catch (\Throwable $e) {
echo $e, PHP_EOL;
}
?>
--EXPECTF--
TypeError: hash_equals(): Argument #2 ($user_string) must be of type string, null given in %s:%d
Stack trace:
#0 %s(%d): hash_equals(Object(SensitiveParameterValue), Object(SensitiveParameterValue))
#1 {main}
ValueError: hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm in %s:%d
Stack trace:
#0 %s(%d): hash_hmac('foo', 'bar', Object(SensitiveParameterValue))
#1 {main}
1 change: 1 addition & 0 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "php.h"
#include "php_ini.h"
#include "php_streams.h"
#include "Zend/zend_attributes.h"
#include "Zend/zend_exceptions.h"
#include "ext/standard/php_string.h"
#include "ext/standard/info.h"
Expand Down
1 change: 1 addition & 0 deletions ext/imap/php_imap.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
*/
const IMAP_GC_TEXTS = UNKNOWN;

/** @sensitive-param $password */
function imap_open(string $mailbox, string $user, string $password, int $flags = 0, int $retries = 0, array $options = []): IMAP\Connection|false {}

function imap_reopen(IMAP\Connection $imap, string $mailbox, int $flags = 0, int $retries = 0): bool {}
Expand Down
4 changes: 3 additions & 1 deletion ext/imap/php_imap_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "php.h"
#include "php_ini.h"
#include "Zend/zend_attributes.h"

#include <stddef.h>

Expand Down
14 changes: 14 additions & 0 deletions ext/ldap/ldap.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@
#endif

#ifdef HAVE_ORALDAP
/**
* @sensitive-param $password
*/
function ldap_connect(?string $uri = null, int $port = 389, string $wallet = UNKNOWN, string $password = UNKNOWN, int $auth_mode = GSLC_SSL_NO_AUTH): LDAP\Connection|false {}
#else
function ldap_connect(?string $uri = null, int $port = 389): LDAP\Connection|false {}
Expand All @@ -620,11 +623,20 @@ function ldap_unbind(LDAP\Connection $ldap): bool {}
/** @alias ldap_unbind */
function ldap_close(LDAP\Connection $ldap): bool {}

/**
* @sensitive-param $password
*/
function ldap_bind(LDAP\Connection $ldap, ?string $dn = null, ?string $password = null): bool {}

/**
* @sensitive-param $password
*/
function ldap_bind_ext(LDAP\Connection $ldap, ?string $dn = null, ?string $password = null, ?array $controls = null): LDAP\Result|false {}

#ifdef HAVE_LDAP_SASL
/**
* @sensitive-param $password
*/
function ldap_sasl_bind(LDAP\Connection $ldap, ?string $dn = null, ?string $password = null, ?string $mech = null, ?string $realm = null, ?string $authc_id = null, ?string $authz_id = null, ?string $props = null): bool {}
#endif

Expand Down Expand Up @@ -779,6 +791,8 @@ function ldap_exop(LDAP\Connection $ldap, string $request_oid, ?string $request_
#ifdef HAVE_LDAP_PASSWD
/**
* @param array $controls
* @sensitive-param $old_password
* @sensitive-param $new_password
*/
function ldap_exop_passwd(LDAP\Connection $ldap, string $user = "", string $old_password = "", string $new_password = "", &$controls = null): string|bool {}
#endif
Expand Down
15 changes: 14 additions & 1 deletion ext/ldap/ldap_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "php_mysqli.h"
#include "php_mysqli_structs.h"
#include "mysqli_priv.h"
#include "zend_attributes.h"
#include "zend_exceptions.h"
#include "ext/spl/spl_exceptions.h"
#include "zend_interfaces.h"
Expand Down
10 changes: 9 additions & 1 deletion ext/mysqli/mysqli.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function autocommit(bool $enable): bool {}
public function begin_transaction(int $flags = 0, ?string $name = null): bool {}

/**
* @sensitive-param $password
* @tentative-return-type
* @alias mysqli_change_user
*/
Expand All @@ -174,6 +175,7 @@ public function close() {} // TODO make return type void
public function commit(int $flags = 0, ?string $name = null): bool {}

/**
* @sensitive-param $password
* @tentative-return-type
* @alias mysqli_connect
* @no-verify
Expand Down Expand Up @@ -287,6 +289,7 @@ public function prepare(string $query): mysqli_stmt|false {}
public function query(string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool {}

/**
* @sensitive-param $password
* @tentative-return-type
* @alias mysqli_real_connect
*/
Expand Down Expand Up @@ -740,6 +743,7 @@ function mysqli_autocommit(mysqli $mysql, bool $enable): bool {}

function mysqli_begin_transaction(mysqli $mysql, int $flags = 0, ?string $name = null): bool {}

/** @sensitive-param $password */
function mysqli_change_user(mysqli $mysql, string $username, string $password, ?string $database): bool {}

/** @refcount 1 */
Expand All @@ -750,7 +754,10 @@ function mysqli_close(mysqli $mysql): bool {} // TODO make return type void

function mysqli_commit(mysqli $mysql, int $flags = 0, ?string $name = null): bool {}

/** @refcount 1 */
/**
* @refcount 1
* @sensitive-param $password
*/
function mysqli_connect(
?string $hostname = null,
?string $username = null,
Expand Down Expand Up @@ -925,6 +932,7 @@ function mysqli_report(int $flags): bool {}
/** @refcount 1 */
function mysqli_query(mysqli $mysql, string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool {}

/** @sensitive-param $password */
function mysqli_real_connect(
mysqli $mysql,
?string $hostname = null,
Expand Down
8 changes: 7 additions & 1 deletion ext/mysqli/mysqli_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ext/oci8/oci8.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "php.h"
#include "ext/standard/info.h"
#include "php_ini.h"
#include "zend_attributes.h"
#include "zend_smart_str.h"

#ifdef HAVE_OCI8
Expand Down Expand Up @@ -385,6 +386,8 @@ PHP_MINIT_FUNCTION(oci)

REGISTER_LONG_CONSTANT("OCI_FO_RETRY", OCI_FO_RETRY, CONST_CS | CONST_PERSISTENT);

register_oci8_symbols(module_number);

return SUCCESS;
}

Expand Down
14 changes: 12 additions & 2 deletions ext/oci8/oci8.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,32 +294,42 @@ function oci_close($connection): ?bool {}
*/
function ocilogoff($connection): ?bool {}

/** @return resource|false */
/**
* @sensitive-param $password
Copy link
Member

@kocsismate kocsismate Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please put the @sensitive-param tag below the @return (and @param) tags

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, the current order makes sense! Just make sure that @sensitive-param is below @param.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify: Below all @params or just below the corresponding @param?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'd say below all @params. But as far as I see, we have precedence for both styles

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, based on looking through a few of the other files I've done the following:

@param
@sensitive-param
@return
@alias
@refcount
@deprecated

* @return resource|false
*/
function oci_new_connect(string $username, string $password, ?string $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT) {}

/**
* @sensitive-param $password
* @return resource|false
* @alias oci_new_connect
* @deprecated
*/
function ocinlogon(string $username, string $password, ?string $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT) {}

/**
* @sensitive-param $password
* @return resource|false
*/
function oci_connect(string $username, string $password, ?string $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT) {}

/**
* @sensitive-param $password
* @return resource|false
* @alias oci_connect
* @deprecated
*/
function ocilogon(string $username, string $password, ?string $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT) {}

/** @return resource|false */
/**
* @sensitive-param $password
* @return resource|false
*/
function oci_pconnect(string $username, string $password, ?string $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT) {}

/**
* @sensitive-param $password
* @return resource|false
* @alias oci_pconnect
* @deprecated
Expand Down
Loading