ZupIT/horusec

tests: create unit tests for rules of horusec-engine

Opened this issue · 6 comments

We currently only have unit tests for the Leaks rules. We need to implement tests for other languages/technologies. These tests need to validate both safe code and insecure code to ensure that false positive and false negative coverage.

Theses tests should be added on the respective packages for each language that engine support. These packages can be founded on engines package.

To implement these tests we can use the tests already created for Leaks as example.

These tests should fill an array of testutil.RuleTestCase with all scenarios of tests. In the TestRulesVulnerableCode test fill the name, rule, src and findings fields, and in the TestRulesSafeCode test the name, rule and src fields.

The name field should have the rule id as in the existing examples of Leaks. The findings field must contain a list of vulnerabilities that the rule informed in the rule parameter must return using as input the src field which contains the vulnerable code. For better organization it is recommended that vulnerable and safe codes be created in a file samples_test.go like in leaks tests and referenced in the test cases.

Tests to be implemented of the leaks language:
  • HS-LEAKS-1
  • HS-LEAKS-2
  • HS-LEAKS-3
  • HS-LEAKS-4
  • HS-LEAKS-5
  • HS-LEAKS-6
  • HS-LEAKS-7
  • HS-LEAKS-8
  • HS-LEAKS-9
  • HS-LEAKS-10
  • HS-LEAKS-11
  • HS-LEAKS-12
  • HS-LEAKS-13
  • HS-LEAKS-14
  • HS-LEAKS-15
  • HS-LEAKS-16
  • HS-LEAKS-17
  • HS-LEAKS-18
  • HS-LEAKS-19
  • HS-LEAKS-20
  • HS-LEAKS-21
  • HS-LEAKS-22
  • HS-LEAKS-23
  • HS-LEAKS-24
  • HS-LEAKS-25
  • HS-LEAKS-26
  • HS-LEAKS-27
  • HS-LEAKS-28
Tests to be implemented of the csharp language:
  • HS-CSHARP-1
  • HS-CSHARP-2
  • HS-CSHARP-3
  • HS-CSHARP-4
  • HS-CSHARP-5
  • HS-CSHARP-6
  • HS-CSHARP-7
  • HS-CSHARP-8
  • HS-CSHARP-9
  • HS-CSHARP-10
  • HS-CSHARP-11
  • HS-CSHARP-12
  • HS-CSHARP-13
  • HS-CSHARP-14
  • HS-CSHARP-15
  • HS-CSHARP-16
  • HS-CSHARP-17
  • HS-CSHARP-18
  • HS-CSHARP-19
  • HS-CSHARP-20
  • HS-CSHARP-21
  • HS-CSHARP-22
  • HS-CSHARP-23
  • HS-CSHARP-24
  • HS-CSHARP-25
  • HS-CSHARP-26
  • HS-CSHARP-27
  • HS-CSHARP-28
  • HS-CSHARP-29
  • HS-CSHARP-30
  • HS-CSHARP-31
  • HS-CSHARP-32
  • HS-CSHARP-33
  • HS-CSHARP-34
  • HS-CSHARP-35
  • HS-CSHARP-36
  • HS-CSHARP-37
  • HS-CSHARP-38
  • HS-CSHARP-39
  • HS-CSHARP-40
  • HS-CSHARP-41
  • HS-CSHARP-42
  • HS-CSHARP-43
  • HS-CSHARP-44
  • HS-CSHARP-45
  • HS-CSHARP-46
  • HS-CSHARP-47
  • HS-CSHARP-48
  • HS-CSHARP-49
  • HS-CSHARP-50
  • HS-CSHARP-51
  • HS-CSHARP-52
  • HS-CSHARP-53
  • HS-CSHARP-54
  • HS-CSHARP-55
  • HS-CSHARP-56
  • HS-CSHARP-57
  • HS-CSHARP-58
  • HS-CSHARP-59
  • HS-CSHARP-60
  • HS-CSHARP-61
  • HS-CSHARP-62
  • HS-CSHARP-63
  • HS-CSHARP-64
  • HS-CSHARP-65
  • HS-CSHARP-66
  • HS-CSHARP-67
  • HS-CSHARP-68
  • HS-CSHARP-69
  • HS-CSHARP-70
  • HS-CSHARP-71
  • HS-CSHARP-72
  • HS-CSHARP-73
  • HS-CSHARP-74
Tests to be implemented of the dart language:
  • HS-DART-1
  • HS-DART-2
  • HS-DART-3
  • HS-DART-4
  • HS-DART-5
  • HS-DART-6
  • HS-DART-7
  • HS-DART-8
  • HS-DART-9
  • HS-DART-10
  • HS-DART-11
  • HS-DART-12
  • HS-DART-13
  • HS-DART-14
  • HS-DART-15
  • HS-DART-16
  • HS-DART-17
Tests to be implemented of the java language:
  • HS-JAVA-1
  • HS-JAVA-2
  • HS-JAVA-3
  • HS-JAVA-4
  • HS-JAVA-5
  • HS-JAVA-6
  • HS-JAVA-7
  • HS-JAVA-8
  • HS-JAVA-9
  • HS-JAVA-10
  • HS-JAVA-11
  • HS-JAVA-12
  • HS-JAVA-13
  • HS-JAVA-14
  • HS-JAVA-15
  • HS-JAVA-16
  • HS-JAVA-17
  • HS-JAVA-18
  • HS-JAVA-19
  • HS-JAVA-20
  • HS-JAVA-21
  • HS-JAVA-22
  • HS-JAVA-23
  • HS-JAVA-24
  • HS-JAVA-25
  • HS-JAVA-26
  • HS-JAVA-27
  • HS-JAVA-28
  • HS-JAVA-29
  • HS-JAVA-30
  • HS-JAVA-31
  • HS-JAVA-32
  • HS-JAVA-33
  • HS-JAVA-34
  • HS-JAVA-35
  • HS-JAVA-36
  • HS-JAVA-37
  • HS-JAVA-38
  • HS-JAVA-39
  • HS-JAVA-40
  • HS-JAVA-41
  • HS-JAVA-42
  • HS-JAVA-43
  • HS-JAVA-44
  • HS-JAVA-45
  • HS-JAVA-46
  • HS-JAVA-47
  • HS-JAVA-48
  • HS-JAVA-49
  • HS-JAVA-50
  • HS-JAVA-51
  • HS-JAVA-52
  • HS-JAVA-53
  • HS-JAVA-54
  • HS-JAVA-55
  • HS-JAVA-56
  • HS-JAVA-57
  • HS-JAVA-58
  • HS-JAVA-59
  • HS-JAVA-60
  • HS-JAVA-61
  • HS-JAVA-62
  • HS-JAVA-63
  • HS-JAVA-64
  • HS-JAVA-65
  • HS-JAVA-66
  • HS-JAVA-67
  • HS-JAVA-68
  • HS-JAVA-69
  • HS-JAVA-70
  • HS-JAVA-71
  • HS-JAVA-72
  • HS-JAVA-73
  • HS-JAVA-74
  • HS-JAVA-75
  • HS-JAVA-76
  • HS-JAVA-77
  • HS-JAVA-78
  • HS-JAVA-79
  • HS-JAVA-80
  • HS-JAVA-81
  • HS-JAVA-82
  • HS-JAVA-83
  • HS-JAVA-84
  • HS-JAVA-85
  • HS-JAVA-86
  • HS-JAVA-87
  • HS-JAVA-88
  • HS-JAVA-89
  • HS-JAVA-90
  • HS-JAVA-91
  • HS-JAVA-92
  • HS-JAVA-93
  • HS-JAVA-94
  • HS-JAVA-95
  • HS-JAVA-96
  • HS-JAVA-97
  • HS-JAVA-98
  • HS-JAVA-99
  • HS-JAVA-100
  • HS-JAVA-101
  • HS-JAVA-102
  • HS-JAVA-103
  • HS-JAVA-104
  • HS-JAVA-105
  • HS-JAVA-106
  • HS-JAVA-107
  • HS-JAVA-108
  • HS-JAVA-109
  • HS-JAVA-110
  • HS-JAVA-111
  • HS-JAVA-112
  • HS-JAVA-113
  • HS-JAVA-114
  • HS-JAVA-115
  • HS-JAVA-116
  • HS-JAVA-117
  • HS-JAVA-118
  • HS-JAVA-119
  • HS-JAVA-120
  • HS-JAVA-121
  • HS-JAVA-122
  • HS-JAVA-123
  • HS-JAVA-124
  • HS-JAVA-125
  • HS-JAVA-126
  • HS-JAVA-127
  • HS-JAVA-128
  • HS-JAVA-129
  • HS-JAVA-130
  • HS-JAVA-131
  • HS-JAVA-132
  • HS-JAVA-133
  • HS-JAVA-134
  • HS-JAVA-135
  • HS-JAVA-136
  • HS-JAVA-137
  • HS-JAVA-138
  • HS-JAVA-139
  • HS-JAVA-140
  • HS-JAVA-141
  • HS-JAVA-142
  • HS-JAVA-143
  • HS-JAVA-144
  • HS-JAVA-145
  • HS-JAVA-146
  • HS-JAVA-147
  • HS-JAVA-148
  • HS-JAVA-149
Tests to be implemented of the java and kotlin languages for JVM based:
  • HS-JVM-1
  • HS-JVM-2
  • HS-JVM-3
  • HS-JVM-4
  • HS-JVM-5
  • HS-JVM-6
  • HS-JVM-7
  • HS-JVM-8
  • HS-JVM-9
  • HS-JVM-10
  • HS-JVM-11
  • HS-JVM-12
  • HS-JVM-13
  • HS-JVM-14
  • HS-JVM-15
  • HS-JVM-16
  • HS-JVM-17
  • HS-JVM-18
  • HS-JVM-19
  • HS-JVM-20
  • HS-JVM-21
  • HS-JVM-22
  • HS-JVM-23
  • HS-JVM-24
  • HS-JVM-25
  • HS-JVM-26
  • HS-JVM-27
  • HS-JVM-28
  • HS-JVM-29
  • HS-JVM-30
  • HS-JVM-31
  • HS-JVM-32
  • HS-JVM-33
  • HS-JVM-34
  • HS-JVM-35
  • HS-JVM-36
  • HS-JVM-37
  • HS-JVM-38
  • HS-JVM-39
  • HS-JVM-40
Tests to be implemented of the kubernetes files:
  • HS-KUBERNETES-1
  • HS-KUBERNETES-2
  • HS-KUBERNETES-3
  • HS-KUBERNETES-4
  • HS-KUBERNETES-5
  • HS-KUBERNETES-6
  • HS-KUBERNETES-7
  • HS-KUBERNETES-8
  • HS-KUBERNETES-9
Tests to be implemented of the nginx files:
  • HS-NGINX-1
  • HS-NGINX-2
  • HS-NGINX-3
  • HS-NGINX-4
Tests to be implemented of the javascript language:
  • HS-JAVASCRIPT-1
  • HS-JAVASCRIPT-2
  • HS-JAVASCRIPT-3
  • HS-JAVASCRIPT-4
  • HS-JAVASCRIPT-5
  • HS-JAVASCRIPT-6
  • HS-JAVASCRIPT-7
  • HS-JAVASCRIPT-8
  • HS-JAVASCRIPT-9
  • HS-JAVASCRIPT-10
  • HS-JAVASCRIPT-11
  • HS-JAVASCRIPT-12
  • HS-JAVASCRIPT-13
  • HS-JAVASCRIPT-14
  • HS-JAVASCRIPT-15
  • HS-JAVASCRIPT-16
  • HS-JAVASCRIPT-17
  • HS-JAVASCRIPT-18
  • HS-JAVASCRIPT-19
  • HS-JAVASCRIPT-20
  • HS-JAVASCRIPT-21
  • HS-JAVASCRIPT-22
  • HS-JAVASCRIPT-23
  • HS-JAVASCRIPT-24
  • HS-JAVASCRIPT-25
  • HS-JAVASCRIPT-26
  • HS-JAVASCRIPT-27
  • HS-JAVASCRIPT-28
  • HS-JAVASCRIPT-29
  • HS-JAVASCRIPT-30
  • HS-JAVASCRIPT-31
  • HS-JAVASCRIPT-32
  • HS-JAVASCRIPT-33
  • HS-JAVASCRIPT-34
  • HS-JAVASCRIPT-35
  • HS-JAVASCRIPT-36
  • HS-JAVASCRIPT-37
  • HS-JAVASCRIPT-38
  • HS-JAVASCRIPT-39
  • HS-JAVASCRIPT-40
  • HS-JAVASCRIPT-41
  • HS-JAVASCRIPT-42
  • HS-JAVASCRIPT-43
  • HS-JAVASCRIPT-44
  • HS-JAVASCRIPT-45
  • HS-JAVASCRIPT-46
  • HS-JAVASCRIPT-47
  • HS-JAVASCRIPT-48
  • HS-JAVASCRIPT-49
  • HS-JAVASCRIPT-50
  • HS-JAVASCRIPT-51
  • HS-JAVASCRIPT-52
  • HS-JAVASCRIPT-53
Tests to be implemented of the swift language:
  • HS-SWIFT-1
  • HS-SWIFT-2
  • HS-SWIFT-3
  • HS-SWIFT-4
  • HS-SWIFT-5
  • HS-SWIFT-6
  • HS-SWIFT-7
  • HS-SWIFT-8
  • HS-SWIFT-9
  • HS-SWIFT-10
  • HS-SWIFT-11
  • HS-SWIFT-12
  • HS-SWIFT-13
  • HS-SWIFT-14
  • HS-SWIFT-15
  • HS-SWIFT-16
  • HS-SWIFT-17
  • HS-SWIFT-18
  • HS-SWIFT-19
  • HS-SWIFT-20
  • HS-SWIFT-21
  • HS-SWIFT-22
  • HS-SWIFT-23
  • HS-SWIFT-24

Looking into rules_test.go, I think we could improve csharp rules, so we can analyze if the command injection and xpath injection isn't sanityzing the input, so we should not release a false-positive.

Looking into rules_test.go, I think we could improve csharp rules, so we can analyze if the command injection and xpath injection isn't sanityzing the input, so we should not release a false-positive.

Hello @filipemelo.

Any improvements to the rules are very welcome!

Currently, we only have a regex engine, so somethings can be hard to check some things with it.
It's already in our plans we have a semantic analysis to improve the engine's assertiveness.

Thank you for your interest in contributing and any questions we are at your disposal.

Looking into rules_test.go, I think we could improve csharp rules, so we can analyze if the command injection and xpath injection isn't sanityzing the input, so we should not release a false-positive.

Hello @filipemelo.

Any improvements to the rules are very welcome!

Currently, we only have a regex engine, so somethings can be hard to check some things with it. It's already in our plans we have a semantic analysis to improve the engine's assertiveness.

Thank you for your interest in contributing and any questions we are at your disposal.

  1. How can I help in samantic analysis? Are any issue to this?
  2. Can I write code for all csharp rules or should I let some easy tasks for hacktoberfest event?

Looking into rules_test.go, I think we could improve csharp rules, so we can analyze if the command injection and xpath injection isn't sanityzing the input, so we should not release a false-positive.

Hello @filipemelo.
Any improvements to the rules are very welcome!
Currently, we only have a regex engine, so somethings can be hard to check some things with it. It's already in our plans we have a semantic analysis to improve the engine's assertiveness.
Thank you for your interest in contributing and any questions we are at your disposal.

  1. How can I help in samantic analysis? Are any issue to this?
  2. Can I write code for all csharp rules or should I let some easy tasks for hacktoberfest event?

Hi again @filipemelo.

  1. We do not have any open issue, we are at a very early stage and studying the best way to do it in our scenario.
    In case you want to know more about what we did until now, you can check this branch and also this commit which contains a explanation of what we are thinking.
  2. About writing all csharp rules, it will be much more than welcome. We still have a lot of other rules to test, so you don't have to worry about that.

Finally, thank you again for your contribution, it is very important to us.

About HS-CSHARP-3 - SCS0007 - XML eXternal Entity Injection (XXE).#SCS007
This only happens to version prior to 4.5.2 .Net Framework, wich is each time less used. (release 4.5.2 - 2014-05-05)
Should we implement this and release false positive for beyond this version?

About HS-CSHARP-3 - SCS0007 - XML eXternal Entity Injection (XXE).#SCS007 This only happens to version prior to 4.5.2 .Net Framework, wich is each time less used. (release 4.5.2 - 2014-05-05) Should we implement this and release false positive for beyond this version?

@filipemelo.

As we still don't have any way to verify the version, I believe it would be worth reducing the confidence and add the vulnerable versions in the description.