|
16 | 16 | Result, |
17 | 17 | Rule, |
18 | 18 | ) |
| 19 | +from codemodder.codetf.v2.codetf import ( |
| 20 | + Action, |
| 21 | + DetectionTool, |
| 22 | + PackageAction, |
| 23 | + PackageResult, |
| 24 | + Strategy, |
| 25 | +) |
19 | 26 | from codemodder.codetf.v3.codetf import Finding as FindingV3 |
20 | | -from codemodder.codetf.v3.codetf import FixStatusType, from_v2 |
| 27 | +from codemodder.codetf.v3.codetf import FixStatusType, from_v2, from_v2_result |
21 | 28 |
|
22 | 29 |
|
23 | 30 | @pytest.fixture(autouse=True) |
@@ -189,6 +196,69 @@ def test_v3_finding_id_not_optional(): |
189 | 196 | FindingV3(id=None, rule=Rule(id="foo", name="whatever")) # type: ignore[arg-type] |
190 | 197 |
|
191 | 198 |
|
| 199 | +def test_v2_result_to_v3(): |
| 200 | + result = Result( |
| 201 | + codemod="codeql:java/log-injection", |
| 202 | + summary="Introduced protections against Log Inject ion / Forging attacks", |
| 203 | + description='This change ensures that log messages can\'t contain newline characters, leaving you vulnerable to Log Forging / Log Injection.\n\nIf malicious users can get newline characters into a log message, they can inject and forge new log entries that look like they came from the server, and trick log analysis tools, administrators, and more . This leads to vulnerabilities like Log Injection, Log Forging, and more attacks from there.\n\nOur change simply strips out newline characters from log messages, ensuring that they can \'t be used to forge new log entries.\n```diff\n+ import io.github.pixee.security.Newlines;\n ...\n String orderId = getUserOrderId();\n- log.info("User order ID: " + orderId);\n+ log. info("User order ID: " + Newlines.stripNewlines(orderId));\n```\n', |
| 204 | + detectionTool=DetectionTool(name="CodeQL"), |
| 205 | + references=[ |
| 206 | + Reference( |
| 207 | + url="https://owasp.org/www-community/attacks/Log_Inj ection", |
| 208 | + description="https://owasp.org/www-community/attacks/Log_Injection", |
| 209 | + ), |
| 210 | + Reference( |
| 211 | + url="https://knowledge-base.secureflag.com/vulnerabilities/inadequate_input_validation/log_inject ion_vulnerability.html", |
| 212 | + description="https://knowledge-base.secureflag.com/vulnerabilities/inadequate_input_validation/log_injection_vulnerability.html", |
| 213 | + ), |
| 214 | + Reference( |
| 215 | + url="https://cwe.mit re.org/data/definitions/117.html", |
| 216 | + description="https://cwe.mitre.org/data/definitions/117.html", |
| 217 | + ), |
| 218 | + ], |
| 219 | + properties={}, |
| 220 | + failedFiles=[], |
| 221 | + changeset=[ |
| 222 | + ChangeSet( |
| 223 | + path="app/src/main/java/org/apache /roller/planet/business/fetcher/RomeFeedFetcher.java", |
| 224 | + diff='--- RomeFeedFetcher.java\n+++ RomeFeedFetcher.java\n@@ -26,6 +26,7 @@\n import com.rometools.rome.io.FeedException;\n import com.rometools.rome.io.SyndFeedInput;\n import com.rometools.rome.io.XmlReader;\n+import static io.github.pixee.security.Newlines.stripAll;\n \n import java.io.IOException;\n import java. net.URI;\n@@ -87,7 +88,7 @@\n }\n \n // fetch the feed\n- log.debug("Fetching feed: "+feedURL);\n+ log.debug("Fetching feed: "+stripAll(feedURL));\n SyndFeed feed;\n try {\n feed = fetchFeed(feedURL);', |
| 225 | + changes=[ |
| 226 | + Change( |
| 227 | + lineNumber=90, |
| 228 | + description="Added a call to replace any newlines the value", |
| 229 | + diffSide=DiffSide.LEFT, |
| 230 | + properties={}, |
| 231 | + packageActions=[ |
| 232 | + PackageAction( |
| 233 | + action=Action.ADD, |
| 234 | + result=PackageResult.FAILED, |
| 235 | + package="pkg:maven/io.github.pixee/java-security [email protected]", |
| 236 | + ) |
| 237 | + ], |
| 238 | + fixedFindings=[ |
| 239 | + Finding( |
| 240 | + id="e5ceaca8-4a05-4f8d-ac74-6a822ac69d8f", |
| 241 | + rule=Rule( |
| 242 | + id="log-injection", |
| 243 | + name="Log Injection", |
| 244 | + url="https://codeql.github.com/codeql-query-help/ java/java-log-injection/", |
| 245 | + ), |
| 246 | + ) |
| 247 | + ], |
| 248 | + ) |
| 249 | + ], |
| 250 | + ai=None, |
| 251 | + strategy=Strategy.deterministic, |
| 252 | + provisional=False, |
| 253 | + fixedFindings=None, |
| 254 | + fixQuality=None, |
| 255 | + ) |
| 256 | + ], |
| 257 | + unfixedFindings=[], |
| 258 | + ) |
| 259 | + assert from_v2_result(result) |
| 260 | + |
| 261 | + |
192 | 262 | def test_v2_to_v3_conversion(): |
193 | 263 | with open("tests/samples/codetfv2_sample.codetf", "r") as f: |
194 | 264 | codetfv2 = CodeTF.model_validate_json(f.read()) |
|
0 commit comments