1
0

AppFrameworkTainter.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. use Psalm\CodeLocation;
  7. use Psalm\Plugin\EventHandler\AfterFunctionLikeAnalysisInterface;
  8. use Psalm\Plugin\EventHandler\Event\AfterFunctionLikeAnalysisEvent;
  9. use Psalm\Type\TaintKindGroup;
  10. class AppFrameworkTainter implements AfterFunctionLikeAnalysisInterface {
  11. public static function afterStatementAnalysis(AfterFunctionLikeAnalysisEvent $event): ?bool {
  12. if ($event->getStatementsSource()->getFQCLN() === null) {
  13. return null;
  14. }
  15. if (!$event->getCodebase()->classExtendsOrImplements($event->getStatementsSource()->getFQCLN(), \OCP\AppFramework\Controller::class)) {
  16. return null;
  17. }
  18. if (!($event->getStmt() instanceof PhpParser\Node\Stmt\ClassMethod)) {
  19. return null;
  20. }
  21. if (!$event->getStmt()->isPublic() || $event->getStmt()->isMagic()) {
  22. return null;
  23. }
  24. foreach ($event->getStmt()->params as $i => $param) {
  25. $expr_type = new Psalm\Type\Union([new Psalm\Type\Atomic\TString()]);
  26. $expr_identifier = (strtolower($event->getStatementsSource()->getFQCLN()) . '::' . strtolower($event->getFunctionlikeStorage()->cased_name) . '#' . ($i + 1));
  27. $event->getCodebase()->addTaintSource(
  28. $expr_type,
  29. $expr_identifier,
  30. TaintKindGroup::ALL_INPUT,
  31. new CodeLocation($event->getStatementsSource(), $param)
  32. );
  33. }
  34. return null;
  35. }
  36. }