From 84e7423175f5e52d90c2dc4f255f2aa67af2eb0f Mon Sep 17 00:00:00 2001 From: cgocast Date: Wed, 6 Sep 2023 13:52:55 +0200 Subject: [PATCH 1/2] Detect DoS by sleep vimeo#10178 --- UPGRADING.md | 2 +- config.xsd | 1 + docs/running_psalm/error_levels.md | 1 + docs/running_psalm/issues.md | 1 + docs/running_psalm/issues/TaintedSleep.md | 9 +++++ .../Internal/Codebase/TaintFlowGraph.php | 10 +++++ src/Psalm/Issue/TaintedSleep.php | 8 ++++ src/Psalm/Type/TaintKind.php | 1 + src/Psalm/Type/TaintKindGroup.php | 1 + stubs/CoreGenericFunctions.phpstub | 22 +++++++++++ tests/TaintTest.php | 37 ++++++++++++++++++- 11 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 docs/running_psalm/issues/TaintedSleep.md create mode 100644 src/Psalm/Issue/TaintedSleep.php diff --git a/UPGRADING.md b/UPGRADING.md index 82ca1b2ed52..d7c70b165fa 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -11,7 +11,7 @@ - [BC] The `TDependentListKey` type was removed and replaced with an optional property of the `TIntRange` type. -- [BC] Value of constant `Psalm\Type\TaintKindGroup::ALL_INPUT` changed to reflect a new `TaintKind::INPUT_XPATH` have been added. Accordingly, default values for `$taint` parameters of `Psalm\Codebase::addTaintSource()` and `Psalm\Codebase::addTaintSink()` have been changed as well. +- [BC] Value of constant `Psalm\Type\TaintKindGroup::ALL_INPUT` changed to reflect new `TaintKind::INPUT_SLEEP` and `TaintKind::INPUT_XPATH` have been added. Accordingly, default values for `$taint` parameters of `Psalm\Codebase::addTaintSource()` and `Psalm\Codebase::addTaintSink()` have been changed as well. - [BC] Property `Config::$shepherd_host` was replaced with `Config::$shepherd_endpoint` diff --git a/config.xsd b/config.xsd index eb5f11e2c21..32801507cbb 100644 --- a/config.xsd +++ b/config.xsd @@ -438,6 +438,7 @@ + diff --git a/docs/running_psalm/error_levels.md b/docs/running_psalm/error_levels.md index 90b5d5351b3..25f08d77fa6 100644 --- a/docs/running_psalm/error_levels.md +++ b/docs/running_psalm/error_levels.md @@ -292,6 +292,7 @@ Level 5 and above allows a more non-verifiable code, and higher levels are even - [TaintedInput](issues/TaintedInput.md) - [TaintedLdap](issues/TaintedLdap.md) - [TaintedShell](issues/TaintedShell.md) + - [TaintedSleep](issues/TaintedSleep.md) - [TaintedSql](issues/TaintedSql.md) - [TaintedSSRF](issues/TaintedSSRF.md) - [TaintedSystemSecret](issues/TaintedSystemSecret.md) diff --git a/docs/running_psalm/issues.md b/docs/running_psalm/issues.md index 592225002e7..06c67302d4e 100644 --- a/docs/running_psalm/issues.md +++ b/docs/running_psalm/issues.md @@ -240,6 +240,7 @@ - [TaintedInput](issues/TaintedInput.md) - [TaintedLdap](issues/TaintedLdap.md) - [TaintedShell](issues/TaintedShell.md) + - [TaintedSleep](issues/TaintedSleep.md) - [TaintedSql](issues/TaintedSql.md) - [TaintedSSRF](issues/TaintedSSRF.md) - [TaintedSystemSecret](issues/TaintedSystemSecret.md) diff --git a/docs/running_psalm/issues/TaintedSleep.md b/docs/running_psalm/issues/TaintedSleep.md new file mode 100644 index 00000000000..181cf045c89 --- /dev/null +++ b/docs/running_psalm/issues/TaintedSleep.md @@ -0,0 +1,9 @@ +# TaintedSleep + +Emitted when user-controlled input can be passed into a `sleep` call or similar. + +```php +xpath($expression); }', ], + 'escapeSeconds' => [ + 'code' => ' 'TaintedXpath', ], + 'taintedSleep' => [ + 'code' => ' 'TaintedSleep', + ], + 'taintedUsleep' => [ + 'code' => ' 'TaintedSleep', + ], + 'taintedTimeNanosleepSeconds' => [ + 'code' => ' 'TaintedSleep', + ], + 'taintedTimeNanosleepNanoseconds' => [ + 'code' => ' 'TaintedSleep', + ], + 'taintedTimeSleepUntil' => [ + 'code' => ' 'TaintedSleep', + ], ]; } From b706d38d54e04d923a31faec1dd8d36ca5a2699d Mon Sep 17 00:00:00 2001 From: cgocast Date: Fri, 29 Sep 2023 09:32:19 +0200 Subject: [PATCH 2/2] Update shortcode --- src/Psalm/Issue/TaintedSleep.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Issue/TaintedSleep.php b/src/Psalm/Issue/TaintedSleep.php index 4f2160ae1a1..77c8b3f5ece 100644 --- a/src/Psalm/Issue/TaintedSleep.php +++ b/src/Psalm/Issue/TaintedSleep.php @@ -4,5 +4,5 @@ final class TaintedSleep extends TaintedInput { - public const SHORTCODE = 323; + public const SHORTCODE = 324; }