-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add right-to-left-override character (U+202E) detection
- Loading branch information
Showing
6 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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
Empty file.
This file contains 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,36 @@ | ||
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification | ||
import re | ||
|
||
class RightToLeftOverride(AbstractDetector): | ||
""" | ||
Detect the usage of a Right-To-Left-Override (U+202E) character | ||
""" | ||
|
||
ARGUMENT = 'rtlo' | ||
HELP = 'Right-To-Left-Override control character is used' | ||
IMPACT = DetectorClassification.HIGH | ||
CONFIDENCE = DetectorClassification.HIGH | ||
|
||
WIKI = 'https://github.com/crytic/slither/wiki/Detector-Documentation#right-to-left-override' | ||
WIKI_TITLE = 'Right-To-Left-Override character' | ||
WIKI_DESCRIPTION = 'An attacker can manipulate the logic of the contract by using a right-to-left-override character (U+202E)' | ||
WIKI_EXPLOIT_SCENARIO = ' ' | ||
WIKI_RECOMMENDATION = 'Special control characters should not be allowed' | ||
|
||
def _detect(self): | ||
results = [] | ||
|
||
pattern = re.compile(".*\u202e.*"); | ||
for filename, source in self.slither.source_code.items(): | ||
info = "{} contains a unicode right-to-left-override character:\n".format(filename) | ||
found = False | ||
for match in pattern.finditer(source): | ||
match_line = match.group(0) | ||
info += "\t- {}\n".format(match_line) | ||
found = True | ||
|
||
if found: | ||
json = self.generate_json_result(info) | ||
results.append(json) | ||
|
||
return results |
This file contains 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 @@ | ||
[{"check": "rtlo", "impact": "High", "confidence": "High", "description": "tests/right_to_left_override.sol contains a unicode right-to-left-override character:\n\t- test1(/*A\u202e/*B*/2 , 1/*\u202d\n", "elements": []}] |
This file contains 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,15 @@ | ||
//pragma solidity ^0.4.24; | ||
|
||
contract A | ||
{ | ||
function test() public pure | ||
{ | ||
test1(/*A/*B*/2 , 1/* | ||
/*C */,3); | ||
} | ||
|
||
function test1(uint a, uint b, uint c) internal pure | ||
{ | ||
a = b + c; | ||
} | ||
} |