Skip to content

Commit 8764396

Browse files
authored
Merge branch 'master' into ssrf-url-name-test
2 parents 9377826 + 507783e commit 8764396

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
827827
lines.indented {
828828
lines.add("get(\"${verifier.stub}\")")
829829
lines.indented {
830-
lines.add(".withMetadata(Metadata.metadata().attr(\"ssrf\", \"${action.getName()}\"))")
830+
lines.add(".withMetadata(Metadata.metadata().attr(SSRF_METADATA_TAG, \"${action.getName()}\"))")
831831
lines.add(".atPriority(1)")
832832
lines.add(".willReturn(")
833833
lines.indented {
@@ -857,21 +857,14 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
857857
}
858858

859859
private fun handleCallbackVerifierRequests(lines: Lines, action: Action, verifier: ActionStubMapping, assertTrue: Boolean) {
860+
val verifierHasReceivedRequestsCheck = "verifierHasReceivedRequests(${verifier.getVerifierName()}, \"${action.getName()}\")"
860861
if (assertTrue) {
861862
lines.addSingleCommentLine("Verifying that the request is successfully made to HttpCallbackVerifier after test execution.")
862-
lines.add("assertTrue(${verifier.getVerifierName()}")
863+
lines.addStatement("assertTrue($verifierHasReceivedRequestsCheck)")
863864
} else {
864865
lines.addSingleCommentLine("Verifying that there are no requests made to HttpCallbackVerifier before test execution.")
865-
lines.add("assertFalse(${verifier.getVerifierName()}")
866+
lines.addStatement("assertFalse($verifierHasReceivedRequestsCheck)")
866867
}
867-
lines.indented {
868-
if (format.isKotlin()) {
869-
lines.add(".allServeEvents")
870-
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
871-
lines.add(".any { it.stubMapping.metadata.getString(\"ssrf\") == \"${action.getName()}\" }")
872-
}
873-
}
874-
lines.add(")")
875868
}
876869

877870
}

core/src/main/kotlin/org/evomaster/core/output/service/TestSuiteWriter.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ class TestSuiteWriter {
643643
if (config.ssrf && solution.hasSsrfFaults()) {
644644
httpCallbackVerifier.getActionVerifierMappings().forEach { v ->
645645
addStatement("private static WireMockServer ${v.getVerifierName()}", lines)
646+
addStatement("private static final String SSRF_METADATA_TAG = \"SSRF\"", lines)
646647
}
647648
}
648649

@@ -674,7 +675,9 @@ class TestSuiteWriter {
674675
if (config.ssrf && solution.hasSsrfFaults()) {
675676
httpCallbackVerifier.getActionVerifierMappings().forEach { v ->
676677
addStatement("private lateinit var ${v.getVerifierName()}: WireMockServer", lines)
678+
addStatement("private const val SSRF_METADATA_TAG: String = \"SSRF\" ", lines)
677679
}
680+
assertionUtilFunctionForSSRF(lines, config.outputFormat)
678681
}
679682

680683
if(config.problemType == EMConfig.ProblemType.WEBFRONTEND){
@@ -1036,6 +1039,10 @@ class TestSuiteWriter {
10361039

10371040
initTestMethod(solution, lines, testSuiteFileName)
10381041
lines.addEmpty(2)
1042+
1043+
if (config.ssrf && solution.hasSsrfFaults() && config.outputFormat.isJavaOrKotlin()) {
1044+
assertionUtilFunctionForSSRF(lines, config.outputFormat)
1045+
}
10391046
}
10401047

10411048

@@ -1144,4 +1151,37 @@ class TestSuiteWriter {
11441151
.toList()
11451152
}
11461153

1154+
private fun assertionUtilFunctionForSSRF(lines: Lines, format: OutputFormat) {
1155+
lines.addEmpty(1)
1156+
1157+
val methodComment = "Method to verify whether the HttpCallbackVerifier has received any requests."
1158+
when {
1159+
format.isKotlin() -> {
1160+
lines.addSingleCommentLine(methodComment)
1161+
lines.add("fun verifierHasReceivedRequests(verifier: WireMockServer, actionName: String) : Boolean")
1162+
}
1163+
format.isJava() -> {
1164+
lines.startCommentBlock()
1165+
lines.addBlockCommentLine(methodComment)
1166+
lines.endCommentBlock()
1167+
lines.add("public static boolean verifierHasReceivedRequests(WireMockServer verifier, String actionName)")
1168+
}
1169+
}
1170+
lines.block {
1171+
lines.add("return verifier")
1172+
lines.indented {
1173+
if (format.isKotlin()) {
1174+
lines.add(".allServeEvents")
1175+
lines.add(".filter { it.wasMatched && it.stubMapping.metadata != null }")
1176+
lines.add(".any { it.stubMapping.metadata.getString(SSRF_METADATA_TAG) == actionName }")
1177+
}
1178+
if (format.isJava()) {
1179+
lines.add(".getAllServeEvents()")
1180+
lines.add(".stream().filter( r -> r.getWasMatched() && r.getStubMapping().getMetadata() != null)")
1181+
lines.add(".anyMatch( r -> r.getStubMapping().getMetadata().getString(SSRF_METADATA_TAG).equals(actionName));")
1182+
}
1183+
}
1184+
}
1185+
}
1186+
11471187
}

docs/publications.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ Also, some of these papers provides full replication packages, which are linked
2323

2424
## Peer-Reviewed Publications
2525

26+
### 2026
27+
28+
* S. Seran, G. Bhandari, A. Arcuri.
29+
*Detecting Server-Side Request Forgery (SSRF) Vulnerabilities In REST API Fuzz Testing*.
30+
IEEE International Workshop on Search-Based and Fuzz Testing (SBFT).
31+
(To appear)
32+
2633
### 2025
2734

2835
* A. Golmohammadi, M. Zhang, A. Arcuri.

0 commit comments

Comments
 (0)