Skip to content

Commit b83a587

Browse files
authored
Merge pull request #1636 from WebFuzzing/auth-issue-in-http-oracle
Auth issue in http oracle
2 parents 5ecc46d + 839da3a commit b83a587

11 files changed

Lines changed: 54 additions & 19 deletions

File tree

core/src/main/kotlin/org/evomaster/core/problem/enterprise/auth/AuthenticationInfo.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ abstract class AuthenticationInfo(
2424
* this forced in [AuthSettings]
2525
*/
2626
fun isDifferentFrom(other: AuthenticationInfo) = this.name != other.name
27+
28+
fun isNoAuth() = NoAuth::class.java.isAssignableFrom(this.javaClass)
2729
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package org.evomaster.core.problem.enterprise.auth
22

33

4-
interface NoAuth
4+
interface NoAuth{
5+
6+
companion object{
7+
const val NAME = "NoAuth"
8+
}
9+
}

core/src/main/kotlin/org/evomaster/core/problem/httpws/auth/AuthUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ object AuthUtils {
347347
* Check if we have valid credentials, but got 401
348348
*/
349349
fun checkUnauthorizedWithAuth(status: Int, a: HttpWsAction) : Boolean{
350-
if (status == 401 && a.auth !is NoAuth && !a.auth.requireMockHandling) {
350+
if (status == 401 && !a.auth.isNoAuth() && !a.auth.requireMockHandling) {
351351
/*
352352
if the endpoint itself is to get auth info, we might exclude auth check for it
353353
eg,

core/src/main/kotlin/org/evomaster/core/problem/httpws/auth/HttpWsAuthenticationInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.evomaster.core.problem.httpws.auth
22

33
import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto
44
import org.evomaster.core.problem.enterprise.auth.AuthenticationInfo
5+
import org.evomaster.core.problem.enterprise.auth.NoAuth
56
import org.evomaster.core.problem.rest.data.RestCallAction
67
import org.evomaster.core.search.action.Action
78

@@ -33,8 +34,7 @@ open class HttpWsAuthenticationInfo(
3334

3435
init {
3536

36-
//FIXME "NoAuth" constant
37-
if(headers.isEmpty() && name != "NoAuth" && endpointCallLogin==null){
37+
if(headers.isEmpty() && name != NoAuth.NAME && endpointCallLogin==null){
3838
throw IllegalArgumentException("Missing info")
3939
}
4040
}

core/src/main/kotlin/org/evomaster/core/problem/httpws/auth/HttpWsNoAuth.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package org.evomaster.core.problem.httpws.auth
33
import org.evomaster.core.problem.enterprise.auth.NoAuth
44

55

6-
class HttpWsNoAuth : HttpWsAuthenticationInfo("NoAuth", listOf(), null, false, null), NoAuth
6+
class HttpWsNoAuth : HttpWsAuthenticationInfo(NoAuth.NAME, listOf(), null, false, null), NoAuth

core/src/main/kotlin/org/evomaster/core/problem/rest/builder/RestIndividualSelectorUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ object RestIndividualSelectorUtils {
6060

6161
if(authenticated != null) {
6262
// authenticated or not
63-
if (authenticated == true && action.auth is NoAuth) {
63+
if (authenticated && action.auth.isNoAuth()) {
6464
return false
6565
}
66-
if(authenticated == false && action.auth !is NoAuth) {
66+
if(!authenticated && !action.auth.isNoAuth()) {
6767
return false
6868
}
6969
}

core/src/main/kotlin/org/evomaster/core/problem/rest/oracle/RestSecurityOracle.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class RestSecurityOracle {
160160
log.warn("Missing action result with id: ${it.getLocalId()}}")
161161
false
162162
} else {
163-
it.auth !is NoAuth && ar.getStatusCode() == 401
163+
!it.auth.isNoAuth() && ar.getStatusCode() == 401
164164
}
165165
}
166166
.filter {
@@ -469,7 +469,7 @@ class RestSecurityOracle {
469469

470470
if((a.verb == HttpVerb.PUT || a.verb == HttpVerb.PATCH || a.verb == HttpVerb.DELETE)
471471
&& faultyPaths.contains(a.path)
472-
&& a.auth is NoAuth
472+
&& a.auth.isNoAuth()
473473
&& StatusGroup.G_2xx.isInGroup(r.getStatusCode())){
474474

475475
// For PUT, check if it's 201 (resource creation - might be OK)
@@ -510,7 +510,7 @@ class RestSecurityOracle {
510510
val a = individual.seeMainExecutableActions()[index]
511511
val r = actionResults.find { it.sourceLocalId == a.getLocalId() } as RestCallResult
512512

513-
if(a.auth is NoAuth && faultyEndpoints.contains(a.getName()) && StatusGroup.G_2xx.isInGroup(r.getStatusCode())){
513+
if(a.auth.isNoAuth() && faultyEndpoints.contains(a.getName()) && StatusGroup.G_2xx.isInGroup(r.getStatusCode())){
514514
val scenarioId = idMapper.handleLocalTarget(
515515
idMapper.getFaultDescriptiveId(DefinedFaultCategory.SECURITY_IGNORE_ANONYMOUS, a.getName())
516516
)
@@ -562,7 +562,7 @@ class RestSecurityOracle {
562562
): Boolean{
563563
verifySampleType(individual)
564564

565-
if(action.auth is NoAuth){
565+
if(action.auth.isNoAuth()){
566566
return false
567567
}
568568
if((actionResults.find { it.sourceLocalId == action.getLocalId() } as RestCallResult).getStatusCode() != 401){
@@ -635,7 +635,7 @@ class RestSecurityOracle {
635635
.getStatusCode())
636636
}.filter {
637637
// check if the action is not authenticated
638-
it.auth is NoAuth
638+
it.auth.isNoAuth()
639639
}
640640

641641
return (a403.isNotEmpty() || a401.isNotEmpty()) && a2xxWithoutAuth.isNotEmpty()
@@ -684,7 +684,7 @@ class RestSecurityOracle {
684684

685685
// Check for write operations without authentication that return 2xx
686686
val anonymousWriteActions = actionsWithResults.filter {
687-
it.auth is NoAuth &&
687+
it.auth.isNoAuth() &&
688688
StatusGroup.G_2xx.isInGroup((actionResults.find { r -> r.sourceLocalId == it.getLocalId() } as RestCallResult)
689689
.getStatusCode())
690690
}

core/src/main/kotlin/org/evomaster/core/problem/rest/service/HttpSemanticsService.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,16 @@ class HttpSemanticsService : TimeBoxedPhase{
425425
when (k) {
426426
401 -> modifyCopy.auth = HttpWsNoAuth()
427427
403 -> {
428-
val otherAuths = sampler.authentications
429-
.getAllOthers(getAction.auth.name, HttpWsAuthenticationInfo::class.java)
430-
if (otherAuths.isEmpty()) return
431-
modifyCopy.auth = otherAuths.first()
428+
if(getAction.auth.isNoAuth()){
429+
//in theory shouldn't happen, as should get 401, but API might be faulty... or return
430+
// 403 instead of 404 on non-existing resources
431+
modifyCopy.auth = HttpWsNoAuth()
432+
} else {
433+
val otherAuths = sampler.authentications
434+
.getAllOthers(getAction.auth.name, HttpWsAuthenticationInfo::class.java)
435+
if (otherAuths.isEmpty()) return
436+
modifyCopy.auth = otherAuths.first()
437+
}
432438
}
433439
else -> modifyCopy.auth = getAction.auth
434440
}

core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestSecurityBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ class RestSecurityBuilder : TimeBoxedPhase {
14791479
creationEndpoint.path
14801480
)
14811481
val creationAction = creationIndividual.individual.seeMainExecutableActions()[actionIndexForCreation]
1482-
assert(creationAction.auth !is NoAuth)
1482+
assert(!creationAction.auth.isNoAuth())
14831483

14841484
//we don't need anything after the creation action
14851485
val sliced = RestIndividualBuilder.sliceAllCallsInIndividualAfterAction(
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.evomaster.core.problem.rpc.auth
22

3+
import org.evomaster.core.problem.enterprise.auth.NoAuth
4+
35
/**
46
* representing RPCAction without auth setup
57
*/
6-
class RPCNoAuth : RPCAuthenticationInfo("NoAuth", true, -1)
8+
class RPCNoAuth : RPCAuthenticationInfo(NoAuth.NAME, true, -1), NoAuth

0 commit comments

Comments
 (0)