Skip to content

Conversation

@kingthorin
Copy link
Member

@kingthorin kingthorin commented Oct 17, 2024

Overview

  • CHANGELOG > Added change note.
  • Message.properties > Added key/value pair supporting the new Alert details.
  • PathTraversalScanRule > Updated to include Other Info on Alerts when applicable.
  • PathTraversalScanRuleUnitTest > Updated to assert Other Info or lack thereof where applicable, also assure appropriate skipping due to pre-conditions.

Related Issues

Checklist

  • [na] Update help
  • Update changelog
  • Run ./gradlew spotlessApply for code formatting
  • Write tests
  • Check code coverage
  • Sign-off commits
  • Squash commits
  • Use a descriptive title

@thc202
Copy link
Member

thc202 commented Oct 18, 2024

This does not seem to address the FP reported in the referenced issue.

@kingthorin
Copy link
Member Author

No it simply provides further context. IMHO it will be rare for all 5 of the nix matches to happen.

Do you want me to also exclude JS/CSS/Binary'ish because that's an option too which I could add to this PR.

@thc202
Copy link
Member

thc202 commented Oct 18, 2024

Not sure how rare is since JS chunks/libs tend to have lot of data, but we should not close the issue if it does not address it.

That would be better to address the issue (though the evidence match done beforehand should have caught the reported case, if actually static content).

@kingthorin
Copy link
Member Author

Okay I'll make further changes.

@kingthorin
Copy link
Member Author

This rule doesn't seem to pre-check the response. I'll tackle that as well.

@kingthorin
Copy link
Member Author

Addressed review, further pre-checks as discussed still coming 😁

@kingthorin kingthorin force-pushed the pathtrav-details branch 2 times, most recently from 6cdb014 to a9c8485 Compare October 19, 2024 20:55
@kingthorin kingthorin changed the title ascanrules: Path Traversal add Other Info for directory match Alerts ascanrules: Path Traversal add details for dir match Alerts & reduce FPs Oct 19, 2024
@kingthorin
Copy link
Member Author

Now w/ pre-checks.

@psiinon
Copy link
Member

psiinon commented Feb 21, 2025

Logo
Checkmarx One – Scan Summary & Detailsfb8ede2c-6d02-403e-afad-c80f2c638a79

Great job! No new security vulnerabilities introduced in this pull request

@kingthorin
Copy link
Member Author

I've rebased this to current. I believe all the previous feedback has been addressed.

Please correct me if I'm wrong.

@kingthorin
Copy link
Member Author

Rebased current, and reviewed previous comments. As far as I see they're all addressed.

@thc202
Copy link
Member

thc202 commented Mar 10, 2025

Probably better to update the help to mention the resources that will be skipped. Although on second thought, maybe we should go with the precheck to start with.

@kingthorin
Copy link
Member Author

Probably better to update the help to mention the resources that will be skipped. Although on second thought, maybe we should go with the precheck to start with.

Do you mean split up the changes, or do the pre-check before the resource checks?

@thc202
Copy link
Member

thc202 commented Mar 10, 2025

Split up, not skip resources for now.

@kingthorin
Copy link
Member Author

Thanks for the review. It's good to get this moving again.

@kingthorin
Copy link
Member Author

Tweaked.

Resource Checking that was trimmed
# Note this was a diff after removal, so these actually need to be added if deemed necessary in the future
diff --git a/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRule.java b/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRule.java
index 32e85e330b..2392b1a806 100644
--- a/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRule.java
+++ b/addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRule.java
@@ -579,13 +579,6 @@ public class PathTraversalScanRule extends AbstractAppParamPlugin
     }
 
     private static boolean isGoodCandidate(HttpMessage msg, Tech targetTech) {
-        if (ResourceIdentificationUtils.isJavaScript(msg)
-                || ResourceIdentificationUtils.isCss(msg)
-                || ResourceIdentificationUtils.responseContainsControlChars(msg)) {
-
-            return false;
-        }
-
         if (targetTech == Tech.Windows) {
             return DirNamesContentsMatcher.matchWinDirectories(msg.getResponseBody().toString())
                     == null;
diff --git a/addOns/ascanrules/src/test/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRuleUnitTest.java b/addOns/ascanrules/src/test/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRuleUnitTest.java
index 51a7b7e2d5..a7e4a91766 100644
--- a/addOns/ascanrules/src/test/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRuleUnitTest.java
+++ b/addOns/ascanrules/src/test/java/org/zaproxy/zap/extension/ascanrules/PathTraversalScanRuleUnitTest.java
@@ -389,30 +389,6 @@ class PathTraversalScanRuleUnitTest extends ActiveScannerTest<PathTraversalScanR
         assertThat(alertsRaised, hasSize(0));
     }
 
-    @ParameterizedTest
-    @ValueSource(strings = {"/styles.css", "/code.js"})
-    void shouldSkipIfReqPathIsCssOrJs(String path) throws Exception {
-        // Given
-        rule.init(getHttpMessage(path + "?p=v"), parent);
-        // When
-        rule.scan();
-        // Then
-        assertThat(httpMessagesSent, hasSize(equalTo(0)));
-    }
-
-    @ParameterizedTest
-    @CsvSource({"/styles/, text/css", "/code, text/javascript"})
-    void shouldSkipIfResponseIsCssOfJs(String path, String contentType) throws Exception {
-        // Given
-        HttpMessage msg = getHttpMessage(path + "?p=v");
-        msg.getResponseHeader().setHeader(HttpResponseHeader.CONTENT_TYPE, contentType);
-        rule.init(msg, parent);
-        // When
-        rule.scan();
-        // Then
-        assertThat(httpMessagesSent, hasSize(equalTo(0)));
-    }
-
     @ParameterizedTest
     @CsvSource({
         // Windows will always happen before ignoring Linux, if only Linux pre-check matches

Comment on lines +420 to +449
List.of(
"c:/",
"c:\\",
"..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\",
"\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\",
"file:///c:/",
"file:///c:\\",
"file:\\\\\\c:\\",
"file:\\\\\\c:/",
"file:\\\\\\",
"d:\\",
"d:/",
"file:///d:/",
"file:///d:\\",
"file:\\\\\\d:\\",
"file:\\\\\\d:/")),
// List win dirs on attack, but skip linux payloads since it has linux
// evidence to start with
Arguments.of(
new ListWinDirsOnAttack("/", "p", "c:/"),
"foo etc root tmp bin boot dev home mnt opt proc bar",
List.of(
"/",
"../../../../../../../../../../../../../../../../",
"/../../../../../../../../../../../../../../../../",
"file:///")));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone sees a better way to do this (and not maintain two lists) lemme know.

@kingthorin
Copy link
Member Author

Deconflicted

@kingthorin
Copy link
Member Author

I believe this is ready for review now.

@kingthorin kingthorin force-pushed the pathtrav-details branch 3 times, most recently from 83c2c7d to ef99847 Compare July 10, 2025 13:32
@thc202
Copy link
Member

thc202 commented Jul 10, 2025

As we talked before the pre-checks were already being done, the claim that this reduces FPs and the referenced issue should be reviewed.

@kingthorin kingthorin changed the title ascanrules: Path Traversal add details for dir match Alerts & reduce FPs ascanrules: Path Traversal add details for dir match Alerts Jul 10, 2025
@kingthorin
Copy link
Member Author

kingthorin commented Jul 10, 2025

Adjusted.

The rule should could also be skipping js/css/binaryish, but we had previously said that should could be done in a separate PR.

... if necessary: #5824 (comment)

@thc202
Copy link
Member

thc202 commented Jul 10, 2025

The shoulds in that sentence are not accurate.

@kingthorin
Copy link
Member Author

kingthorin commented Jul 10, 2025

Could 😀

When things sit for 6, 9, 12 months, don't be surprised if I'm inaccurate 😜 (Edit: To be clear, that's not blame, I know it's been waiting on me.)

@thc202
Copy link
Member

thc202 commented Jul 10, 2025

I'm well aware of what I said, the split was to remove the resource exclusion from this PR (good, we don't want FNs). And the for now does not imply that resource exclusion should (or could, even) be done anyway. This is not a passive rule that can't discern cause and effect.

@kingthorin
Copy link
Member Author

Oh okay, I wasn't looking at it that way. I just figured that the resource exclusions would be more efficient than the pre-check regexes. But now I think I see what you're getting at.
(Linking the comment was for me.)

Anyway this is no longer "fixing" the issue, and I've adjusted the changelog and title to not claim FP reduction.

- CHANGELOG > Added change note.
- Message.properties > Added key/value pair supporting the new Alert
details.
- PathTraversalScanRule > Updated to include Other Info on Alerts when
applicable.
- PathTraversalScanRuleUnitTest > Updated to assert Other Info or lack
thereof where applicable, also assure appropriate skipping due to
pre-conditions.

Signed-off-by: kingthorin <[email protected]>
@thc202 thc202 merged commit d8bc6a1 into zaproxy:main Aug 18, 2025
8 of 9 checks passed
@thc202
Copy link
Member

thc202 commented Aug 18, 2025

Thank you!

@thc202 thc202 removed the backlog label Aug 18, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2025
@kingthorin kingthorin deleted the pathtrav-details branch August 18, 2025 21:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants