-
Notifications
You must be signed in to change notification settings - Fork 7.9k
RFC: Redacting parameters in back traces #7921
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute suppresses the single sensitive argument. | ||
--FILE-- | ||
<?php | ||
|
||
function test(#[SensitiveParameter] $sensitive) | ||
{ | ||
debug_print_backtrace(); | ||
var_dump(debug_backtrace()); | ||
var_dump((new Exception)->getTrace()); | ||
} | ||
|
||
test('sensitive'); | ||
|
||
?> | ||
--EXPECTF-- | ||
#0 %ssensitive_parameter.php(10): test(Object(SensitiveParameterValue)) | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter.php" | ||
["line"]=> | ||
int(10) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
iluuu1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter.php" | ||
["line"]=> | ||
int(10) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Zend/tests/function_arguments/sensitive_parameter_arrow_function.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute suppresses the single sensitive argument for arrow functions. | ||
--FILE-- | ||
<?php | ||
|
||
$test = fn (#[SensitiveParameter] $sensitive) => (new Exception)->getTrace(); | ||
|
||
var_dump($test('sensitive')); | ||
|
||
?> | ||
--EXPECTF-- | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_arrow_function.php" | ||
["line"]=> | ||
int(5) | ||
["function"]=> | ||
string(9) "{closure}" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Zend/tests/function_arguments/sensitive_parameter_closure.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute suppresses the single sensitive argument for closures. | ||
--FILE-- | ||
<?php | ||
|
||
$test = function (#[SensitiveParameter] $sensitive) | ||
{ | ||
debug_print_backtrace(); | ||
var_dump(debug_backtrace()); | ||
var_dump((new Exception)->getTrace()); | ||
}; | ||
|
||
$test('sensitive'); | ||
|
||
?> | ||
--EXPECTF-- | ||
#0 %ssensitive_parameter_closure.php(10): {closure}(Object(SensitiveParameterValue)) | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_closure.php" | ||
["line"]=> | ||
int(10) | ||
["function"]=> | ||
string(9) "{closure}" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_closure.php" | ||
["line"]=> | ||
int(10) | ||
["function"]=> | ||
string(9) "{closure}" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Zend/tests/function_arguments/sensitive_parameter_correctly_captures_original.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--TEST-- | ||
The SensitiveParameterValue replacement value correctly captures the original value. | ||
--FILE-- | ||
<?php | ||
|
||
function test( | ||
$foo, | ||
#[SensitiveParameter] $bar, | ||
$baz | ||
) { | ||
throw new Exception('Error'); | ||
} | ||
|
||
try { | ||
test('foo', 'bar', 'baz'); | ||
echo 'Not reached'; | ||
} catch (Exception $e) { | ||
echo $e->getMessage(), PHP_EOL; | ||
$testFrame = $e->getTrace()[0]; | ||
var_dump($testFrame['function']); | ||
var_dump(count($testFrame['args'])); | ||
var_dump($testFrame['args'][0]); | ||
assert($testFrame['args'][1] instanceof SensitiveParameterValue); | ||
var_dump($testFrame['args'][1]->getValue()); | ||
var_dump($testFrame['args'][2]); | ||
echo "Success", PHP_EOL; | ||
} | ||
|
||
function test2( | ||
$foo, | ||
#[SensitiveParameter] ...$variadic, | ||
) { | ||
throw new Exception('Error 2'); | ||
} | ||
|
||
try { | ||
test2('foo', 'variadic1', 'variadic2', 'variadic3'); | ||
echo 'Not reached'; | ||
} catch (Exception $e) { | ||
echo $e->getMessage(), PHP_EOL; | ||
$testFrame = $e->getTrace()[0]; | ||
var_dump($testFrame['function']); | ||
var_dump(count($testFrame['args'])); | ||
var_dump($testFrame['args'][0]); | ||
assert($testFrame['args'][1] instanceof SensitiveParameterValue); | ||
var_dump($testFrame['args'][1]->getValue()); | ||
assert($testFrame['args'][2] instanceof SensitiveParameterValue); | ||
var_dump($testFrame['args'][2]->getValue()); | ||
assert($testFrame['args'][3] instanceof SensitiveParameterValue); | ||
var_dump($testFrame['args'][3]->getValue()); | ||
echo "Success", PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Error | ||
string(4) "test" | ||
int(3) | ||
string(3) "foo" | ||
string(3) "bar" | ||
string(3) "baz" | ||
Success | ||
Error 2 | ||
string(5) "test2" | ||
int(4) | ||
string(3) "foo" | ||
string(9) "variadic1" | ||
string(9) "variadic2" | ||
string(9) "variadic3" | ||
Success |
72 changes: 72 additions & 0 deletions
72
Zend/tests/function_arguments/sensitive_parameter_eval_call.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute suppresses the single sensitive argument in a function called in eval(). | ||
--FILE-- | ||
<?php | ||
|
||
function test(#[SensitiveParameter] $sensitive) | ||
{ | ||
debug_print_backtrace(); | ||
var_dump(debug_backtrace()); | ||
var_dump((new Exception)->getTrace()); | ||
} | ||
|
||
eval(<<<'EOT' | ||
test('sensitive'); | ||
EOT); | ||
|
||
?> | ||
--EXPECTF-- | ||
#0 %ssensitive_parameter_eval_call.php(11) : eval()'d code(1): test(Object(SensitiveParameterValue)) | ||
#1 %ssensitive_parameter_eval_call.php(11): eval() | ||
array(2) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_call.php(11) : eval()'d code" | ||
["line"]=> | ||
int(1) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
[1]=> | ||
array(3) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_call.php" | ||
["line"]=> | ||
int(11) | ||
["function"]=> | ||
string(4) "eval" | ||
} | ||
} | ||
array(2) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_call.php(11) : eval()'d code" | ||
["line"]=> | ||
int(1) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
[1]=> | ||
array(3) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_call.php" | ||
["line"]=> | ||
int(11) | ||
["function"]=> | ||
string(4) "eval" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Zend/tests/function_arguments/sensitive_parameter_eval_define.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute suppresses the single sensitive argument in a function created in eval(). | ||
--FILE-- | ||
<?php | ||
|
||
eval(<<<'EOT' | ||
function test(#[SensitiveParameter] $sensitive) | ||
{ | ||
debug_print_backtrace(); | ||
var_dump(debug_backtrace()); | ||
var_dump((new Exception)->getTrace()); | ||
} | ||
EOT); | ||
|
||
test('sensitive'); | ||
|
||
?> | ||
--EXPECTF-- | ||
#0 %ssensitive_parameter_eval_define.php(12): test(Object(SensitiveParameterValue)) | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_define.php" | ||
["line"]=> | ||
int(12) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_eval_define.php" | ||
["line"]=> | ||
int(12) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(1) { | ||
[0]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
Zend/tests/function_arguments/sensitive_parameter_extra_arguments.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--TEST-- | ||
The SensitiveParameter attribute does not suppress superfluous arguments if the last parameter is sensitive. | ||
--FILE-- | ||
<?php | ||
|
||
function test( | ||
$non_sensitive, | ||
#[SensitiveParameter] $sensitive, | ||
) | ||
{ | ||
debug_print_backtrace(); | ||
var_dump(debug_backtrace()); | ||
var_dump((new Exception)->getTrace()); | ||
} | ||
|
||
test('foo', 'bar', 'baz'); | ||
|
||
?> | ||
--EXPECTF-- | ||
#0 %ssensitive_parameter_extra_arguments.php(13): test('foo', Object(SensitiveParameterValue), 'baz') | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_extra_arguments.php" | ||
["line"]=> | ||
int(13) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(3) { | ||
[0]=> | ||
string(3) "foo" | ||
[1]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
[2]=> | ||
string(3) "baz" | ||
} | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%ssensitive_parameter_extra_arguments.php" | ||
["line"]=> | ||
int(13) | ||
["function"]=> | ||
string(4) "test" | ||
["args"]=> | ||
array(3) { | ||
[0]=> | ||
string(3) "foo" | ||
[1]=> | ||
object(SensitiveParameterValue)#%d (0) { | ||
} | ||
[2]=> | ||
string(3) "baz" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.