-
Notifications
You must be signed in to change notification settings - Fork 18
Refactored Taint Analysis #216
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
Merged
Merged
Changes from all commits
Commits
Show all changes
117 commits
Select commit
Hold shift + click to select a range
6c679d1
Taint analysis
Lipen 103d20c
Remove unnecessary accept override
Lipen b1a09c9
fix: access flags for unknown methods
sergeypospelov 3ae0bcd
fix: revert 0
sergeypospelov bf97bc3
fix: revert 1
sergeypospelov c5fbc8f
fix: revert 2
sergeypospelov 781e65a
fix: revert 3
sergeypospelov 82f2101
fix: TODO
sergeypospelov 479be4e
fix: revert 5
sergeypospelov 5c9bcf4
Debug messages
Lipen d57d3c4
Make handleControlEvent non-suspend
Lipen 9eab66e
Move getOverrides
Lipen f7f6fc8
Add toString for units
Lipen 4a61f44
Fix summary flows
Lipen 6a8a61a
Fix logger import
Lipen 8bf35bf
Move entry point for taint analysis
Lipen 028fcf6
Delegate to basicConditionEvaluator
Lipen f75a0c3
Rename Runner
Lipen 744679b
Use `computeIfAbsert`, switch to concurrent set
Lipen 79527b9
Make all runner fields private, restore erased types
Lipen 013d0f3
Reuse event instances
Lipen 0d0be06
Remove comments
Lipen 749d4d8
Remove IDEA-specific suppresses
Lipen 789a7b1
Move NPE analysis entry point
Lipen 4e43674
Move timeout to argument
Lipen 4691ab7
Fix debug
Lipen d305cfc
Replace with TODO
Lipen aae64c5
Remove `isSkipped`
Lipen f41c335
Remove old unused code
Lipen 83f0118
Replace with logger
Lipen f0c7c83
Remove
Lipen eef22f1
Remove
Lipen d8f1d35
Remove
Lipen 08c81d1
Cleanup
Lipen f3bad35
Remove
Lipen 88d35e9
Rename UniRunner
Lipen 6045beb
Make pathEdges internal for extension function
Lipen 0fefbb9
Remove
Lipen ef8f0f5
Revert "Delegate to basicConditionEvaluator"
Lipen 1d393a2
Remove
Lipen 6cd9c63
Replace globals with manager constructor argument
Lipen 159866b
Move queueIsNotEmpty
Lipen 05e4f20
Format
Lipen 1e7529b
Use logger
Lipen 4bd389a
Remove types
Lipen b63adb8
Do not add deps
Lipen 67cf2de
Ignore events for non-existing runners
Lipen 5df901e
Make handleControlEvent suspend
Lipen e625b2f
Use computeIfAbsent, remove types
Lipen 6687372
Fix
Lipen b1dd664
Cleanup
Lipen 62ed74d
Timeout 30s in tests
Lipen 020df51
Types
Lipen 8771a1b
Cleanup
Lipen 00b20c4
Make handleControlEvent non-suspend again
Lipen 8570449
Log timeout
Lipen 0af092a
Add explanations for unexpected IsType and AnnotationType conditions
Lipen 8dbe55b
Use isOnHeap
Lipen 7463761
Revert unnecessary changes
Lipen bc82b6e
Add mocking tests for flow functions
Lipen 94ccf10
Remove unnecessary converters to old DomainFact
Lipen ce50333
Add missing config for mocking tests
Lipen 927dbb1
Remove trace logging
Lipen 327af42
Cleanup
Lipen 090adac
Extract aggregates
Lipen c031650
Add test with bidi runner and class unit resolver
Lipen 901e255
Fix visited
Lipen 9611d66
Start analysis of deps
Lipen 6f1a8d0
Review fixes
Lipen 8d531e5
Move toDomainFact
Lipen a83cf68
Report vulnerability for each triggered rule
Lipen b5a0db3
Increase coverage
Lipen 459c9a1
Revert "Increase coverage"
Lipen e1b00e2
Remove old IFDS
Lipen e4c5cc8
Cleanup logs
Lipen eef7118
Types
Lipen ad5a03a
Format
Lipen a350539
Cleanup
Lipen c13092e
Add tests for condition evaluator
Lipen 473c9f7
Fix type
Lipen b7f0da5
Add toString for AnyArgument
Lipen a81add4
Test ContainsMark condition via FactAwareConditionEvaluator
Lipen da3fdd5
Fix BaseAnalysisTest
Lipen 261bff3
Add unused variable analysis
Lipen 2e30243
Cleanup logger config
Lipen fe685fd
Fix trace graph merging
Lipen f95366b
Fix tests
Lipen 365b4cc
Fix unused variable analysis
Lipen 9a69046
Fix SARIF, rename some files and classes
Lipen 8f5a871
Restore CLI
Lipen af8161e
Fix internal function name
Lipen c2d7351
Fix
Lipen ec55566
Remove unnecessary stuff
Lipen f893970
Fix NPE tests
Lipen e0839cc
Fix running analysis from Java
Lipen b506f74
Remove ElementAccessor's dummy constructor
Lipen 8a6a3a0
Use non-nullable T
Lipen 8ea7525
Convert ConditionSimplifier to object
Lipen fcad9bd
Compact toString
Lipen 0ed6f48
Cleanup
Lipen 8cd0891
Use any
Lipen 89c1226
Cleanup
Lipen 05e992d
Remove unnecessary NewVulnerability event for UnusedVariable analysis
Lipen 0cabd92
Remove unnecessary entry points
Lipen b7a2230
Add "entry point" position resolvers
Lipen 3ec515c
Remove comment
Lipen facb51a
Replace comment with TODO
Lipen 62c8770
Remove comments
Lipen 13e9b53
Unify code
Lipen 0f4464b
Add JvmName
Lipen ece975a
Trace
Lipen d70ed76
Add PassThrough rule for Map::put
Lipen 4b720d5
Use info logger level for found sinks
Lipen 41ce66a
Add PassThrough for decodeBase64
Lipen 3ec7809
Add PassThrough rule for Map::replace
Lipen ae76dd6
Fix ConditionMark evaluation, add adhoc for arrays
Lipen b39519f
Do not override tainted arrays
Lipen 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
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
74 changes: 0 additions & 74 deletions
74
jacodb-analysis/src/main/kotlin/org/jacodb/analysis/AnalysisMain.kt
This file was deleted.
Oops, something went wrong.
185 changes: 185 additions & 0 deletions
185
jacodb-analysis/src/main/kotlin/org/jacodb/analysis/config/Condition.kt
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,185 @@ | ||
/* | ||
* Copyright 2022 UnitTestBot contributors (utbot.org) | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jacodb.analysis.config | ||
|
||
import org.jacodb.analysis.ifds.AccessPath | ||
import org.jacodb.analysis.ifds.ElementAccessor | ||
import org.jacodb.analysis.ifds.Maybe | ||
import org.jacodb.analysis.ifds.onSome | ||
import org.jacodb.analysis.ifds.toPath | ||
import org.jacodb.analysis.taint.Tainted | ||
import org.jacodb.api.cfg.JcBool | ||
import org.jacodb.api.cfg.JcConstant | ||
import org.jacodb.api.cfg.JcInt | ||
import org.jacodb.api.cfg.JcStringConstant | ||
import org.jacodb.api.cfg.JcValue | ||
import org.jacodb.api.ext.isAssignable | ||
import org.jacodb.taint.configuration.And | ||
import org.jacodb.taint.configuration.AnnotationType | ||
import org.jacodb.taint.configuration.ConditionVisitor | ||
import org.jacodb.taint.configuration.ConstantBooleanValue | ||
import org.jacodb.taint.configuration.ConstantEq | ||
import org.jacodb.taint.configuration.ConstantGt | ||
import org.jacodb.taint.configuration.ConstantIntValue | ||
import org.jacodb.taint.configuration.ConstantLt | ||
import org.jacodb.taint.configuration.ConstantMatches | ||
import org.jacodb.taint.configuration.ConstantStringValue | ||
import org.jacodb.taint.configuration.ConstantTrue | ||
import org.jacodb.taint.configuration.ContainsMark | ||
import org.jacodb.taint.configuration.IsConstant | ||
import org.jacodb.taint.configuration.IsType | ||
import org.jacodb.taint.configuration.Not | ||
import org.jacodb.taint.configuration.Or | ||
import org.jacodb.taint.configuration.PositionResolver | ||
import org.jacodb.taint.configuration.SourceFunctionMatches | ||
import org.jacodb.taint.configuration.TypeMatches | ||
|
||
open class BasicConditionEvaluator( | ||
internal val positionResolver: PositionResolver<Maybe<JcValue>>, | ||
) : ConditionVisitor<Boolean> { | ||
|
||
override fun visit(condition: ConstantTrue): Boolean { | ||
return true | ||
} | ||
|
||
override fun visit(condition: Not): Boolean { | ||
return !condition.arg.accept(this) | ||
} | ||
|
||
override fun visit(condition: And): Boolean { | ||
return condition.args.all { it.accept(this) } | ||
} | ||
|
||
override fun visit(condition: Or): Boolean { | ||
return condition.args.any { it.accept(this) } | ||
} | ||
|
||
override fun visit(condition: IsConstant): Boolean { | ||
positionResolver.resolve(condition.position).onSome { return it is JcConstant } | ||
return false | ||
} | ||
|
||
override fun visit(condition: IsType): Boolean { | ||
// Note: TaintConfigurationFeature.ConditionSpecializer is responsible for | ||
// expanding IsType condition upon parsing the taint configuration. | ||
error("Unexpected condition: $condition") | ||
} | ||
|
||
override fun visit(condition: AnnotationType): Boolean { | ||
// Note: TaintConfigurationFeature.ConditionSpecializer is responsible for | ||
// expanding AnnotationType condition upon parsing the taint configuration. | ||
error("Unexpected condition: $condition") | ||
sergeypospelov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
override fun visit(condition: ConstantEq): Boolean { | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
return when (val constant = condition.value) { | ||
is ConstantBooleanValue -> { | ||
value is JcBool && value.value == constant.value | ||
} | ||
|
||
is ConstantIntValue -> { | ||
value is JcInt && value.value == constant.value | ||
} | ||
|
||
is ConstantStringValue -> { | ||
// TODO: if 'value' is not string, convert it to string and compare with 'constant.value' | ||
value is JcStringConstant && value.value == constant.value | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
|
||
override fun visit(condition: ConstantLt): Boolean { | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
return when (val constant = condition.value) { | ||
is ConstantIntValue -> { | ||
value is JcInt && value.value < constant.value | ||
} | ||
|
||
else -> error("Unexpected constant: $constant") | ||
} | ||
} | ||
return false | ||
} | ||
|
||
override fun visit(condition: ConstantGt): Boolean { | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
return when (val constant = condition.value) { | ||
is ConstantIntValue -> { | ||
value is JcInt && value.value > constant.value | ||
} | ||
|
||
else -> error("Unexpected constant: $constant") | ||
} | ||
} | ||
return false | ||
} | ||
|
||
override fun visit(condition: ConstantMatches): Boolean { | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
val re = condition.pattern.toRegex() | ||
return re.matches(value.toString()) | ||
} | ||
return false | ||
} | ||
|
||
override fun visit(condition: SourceFunctionMatches): Boolean { | ||
TODO("Not implemented yet") | ||
} | ||
|
||
override fun visit(condition: ContainsMark): Boolean { | ||
error("This visitor does not support condition $condition. Use FactAwareConditionEvaluator instead") | ||
} | ||
|
||
override fun visit(condition: TypeMatches): Boolean { | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
return value.type.isAssignable(condition.type) | ||
} | ||
return false | ||
} | ||
} | ||
|
||
class FactAwareConditionEvaluator( | ||
private val fact: Tainted, | ||
positionResolver: PositionResolver<Maybe<JcValue>>, | ||
) : BasicConditionEvaluator(positionResolver) { | ||
|
||
override fun visit(condition: ContainsMark): Boolean { | ||
if (fact.mark != condition.mark) return false | ||
positionResolver.resolve(condition.position).onSome { value -> | ||
val variable = value.toPath() | ||
|
||
// FIXME: Adhoc for arrays | ||
val variableWithoutStars = variable.removeTrailingElementAccessors() | ||
val factWithoutStars = fact.variable.removeTrailingElementAccessors() | ||
if (variableWithoutStars == factWithoutStars) return true | ||
|
||
return variable == fact.variable | ||
} | ||
return false | ||
} | ||
|
||
private fun AccessPath.removeTrailingElementAccessors(): AccessPath { | ||
val accesses = accesses.toMutableList() | ||
while (accesses.lastOrNull() is ElementAccessor) { | ||
accesses.removeLast() | ||
} | ||
return AccessPath(value, accesses) | ||
} | ||
} |
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.