Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

3.0 KB
Raw Blame
package opensuite.engagement;

import opensuite.engagement.SiteMapCompare.Item;
import opensuite.engagement.SiteMapCompare.Row;
import opensuite.engagement.SiteMapCompare.Verdict;
import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.List;

/** Tests the Compare site maps comparison used for access-control testing. */
public final class SiteMapCompareTest {

    private static Row find(List<Row> rows, String url) {
        for (Row r : rows) if (r.url().equals(url)) return r;
        throw new AssertionError("no row for " + url);
    }

    public void run() {
        Harness.suite("site map compare");

        Harness.test("a similar 2xx in session 2 is an access-control concern", () -> {
            List<Row> rows = SiteMapCompare.compare(
                    List.of(new Item("GET", "/admin", 200, 1000)),
                    List.of(new Item("GET", "/admin", 200, 1010)), 0.05);
            Row r = find(rows, "/admin");
            Expect.equal(r.verdict(), Verdict.SIMILAR, "same status class, lengths within 5%");
            Expect.isTrue(r.accessControlConcern(), "the unauthenticated user still reached /admin");
        });

        Harness.test("a different status is not a concern", () -> {
            List<Row> rows = SiteMapCompare.compare(
                    List.of(new Item("GET", "/admin", 200, 1000)),
                    List.of(new Item("GET", "/admin", 403, 120)), 0.05);
            Row r = find(rows, "/admin");
            Expect.equal(r.verdict(), Verdict.DIFFERENT, "200 vs 403 differ");
            Expect.isFalse(r.accessControlConcern(), "session 2 was denied");
        });

        Harness.test("length beyond tolerance is different", () -> {
            List<Row> rows = SiteMapCompare.compare(
                    List.of(new Item("GET", "/x", 200, 1000)),
                    List.of(new Item("GET", "/x", 200, 2000)), 0.05);
            Expect.equal(find(rows, "/x").verdict(), Verdict.DIFFERENT, "100% longer is different");
        });

        Harness.test("URLs present in only one session are marked", () -> {
            List<Row> rows = SiteMapCompare.compare(
                    List.of(new Item("GET", "/only1", 200, 10)),
                    List.of(new Item("GET", "/only2", 200, 10)), 0.05);
            Expect.equal(find(rows, "/only1").verdict(), Verdict.ONLY_FIRST, "missing from session 2");
            Expect.equal(find(rows, "/only2").verdict(), Verdict.ONLY_SECOND, "missing from session 1");
            Expect.isFalse(find(rows, "/only1").accessControlConcern(), "only-in-1 is no concern");
        });

        Harness.test("a similar non-2xx response is not flagged", () -> {
            List<Row> rows = SiteMapCompare.compare(
                    List.of(new Item("GET", "/login", 302, 0)),
                    List.of(new Item("GET", "/login", 302, 0)), 0.05);
            Row r = find(rows, "/login");
            Expect.equal(r.verdict(), Verdict.SIMILAR, "both redirect identically");
            Expect.isFalse(r.accessControlConcern(), "a 302 is not reaching protected content");
        });
    }
}