Skip to content

Commit 04affa6

Browse files
authored
Merge pull request #55 from designsecurity/staticmethodsource
static methods as custom source
2 parents a178a25 + 0dfc622 commit 04affa6

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

package/src/progpilot/Analysis/VisitorAnalysis.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ public function funcCall(
132132
$this->context->getObjects()->addMyclassToObject($idObjectTmp, $myClassStatic);
133133

134134
$stackClass[0][0] = $myDefStatic;
135+
} else {
136+
// we create a fake instance
137+
$myClass = new MyClass(
138+
$myFuncCall->getLine(),
139+
$myFuncCall->getColumn(),
140+
$myFuncCall->getNameInstance()
141+
);
142+
143+
$listMyFunc[] = [0, $myClass, null, true, null];
135144
}
136145
} else {
137146
$myFunc = $this->context->getFunctions()->getFunction($funcName);

package/src/progpilot/Inputs/MyInputsInternalApi.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,15 @@ public function getSourceByName($myFuncOrDef, $myClass, $dimArray = null)
286286
if (!$mySource->isInstance()
287287
&& empty($mySource->getArrayValue())
288288
&& !$myFuncOrDef->isType(MyFunction::TYPE_FUNC_METHOD)
289-
&& !$myFuncOrDef->isType(MyDefinition::TYPE_PROPERTY)) {
289+
&& !$myFuncOrDef->isType(MyFunction::TYPE_FUNC_STATIC)
290+
&& !$myFuncOrDef->isType(MyDefinition::TYPE_PROPERTY)) {
290291
return $mySource;
291292
}
292293

293294
if ($mySource->isInstance()
294295
&& ($myFuncOrDef->isType(MyFunction::TYPE_FUNC_METHOD)
295-
|| $myFuncOrDef->isType(MyDefinition::TYPE_PROPERTY))) {
296+
|| $myFuncOrDef->isType(MyFunction::TYPE_FUNC_STATIC)
297+
|| $myFuncOrDef->isType(MyDefinition::TYPE_PROPERTY))) {
296298
if (!is_null($myClass) &&
297299
($mySource->getInstanceOfName() === $myClass->getName()
298300
|| $mySource->getInstanceOfName() === $myClass->getExtendsOf())) {

package/src/uptodate_data/php/dev/sources.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{"name": "methodc1arr", "is_function": true, "instanceof": "testc1", "return_array_index": "tainted", "language": "php", "type": "for dev purposes"},
66
{"name": "func1arr", "is_function": true, "return_array_index": "tainted", "language": "php", "type": "for dev purposes"},
77
{"name": "member1", "instanceof": "testc1", "language": "php", "type": "for dev purposes"},
8-
{"name": "vardev", "is_array": true, "array_index": ["tainted"], "language": "php", "type": "for dev purposes"}
8+
{"name": "vardev", "is_array": true, "array_index": ["tainted"], "language": "php", "type": "for dev purposes"},
9+
{"name": "getValue", "is_function": true, "instanceof": "Tools", "language": "php", "type": "for dev purposes"},
10+
{"name": "getValue", "is_function": true, "instanceof": "ToolsClass", "language": "php", "type": "for dev purposes"}
911
]
1012
}

projects/tests/datatest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@
135135
"./tests/data/source21.php",
136136
[["\$title", "0", "xss"]]
137137
],
138+
[
139+
"./tests/data/source22.php",
140+
[["\$getValue_return", "3", "xss"],
141+
["\$getValue_return", "7", "xss"]]
142+
],
138143
[
139144
"./tests/data/sanitizer1.php",
140145
[["\$var7safe", "5", "xss"]]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
echo Tools::getValue();
4+
5+
$foo = new ToolsClass();
6+
7+
echo $foo->getValue();

0 commit comments

Comments
 (0)