|
| 1 | +import java |
| 2 | + |
| 3 | +/** The class `org.springframework.security.config.annotation.web.builders.HttpSecurity`. */ |
| 4 | +class TypeHttpSecurity extends Class { |
| 5 | + TypeHttpSecurity() { |
| 6 | + this |
| 7 | + .hasQualifiedName("org.springframework.security.config.annotation.web.builders", |
| 8 | + "HttpSecurity") |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +/** |
| 13 | + * The class |
| 14 | + * `org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer`. |
| 15 | + */ |
| 16 | +class TypeAuthorizedUrl extends Class { |
| 17 | + TypeAuthorizedUrl() { |
| 18 | + this |
| 19 | + .hasQualifiedName("org.springframework.security.config.annotation.web.configurers", |
| 20 | + "ExpressionUrlAuthorizationConfigurer<HttpSecurity>$AuthorizedUrl<>") |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * The class |
| 26 | + * `org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry`. |
| 27 | + */ |
| 28 | +class TypeAbstractRequestMatcherRegistry extends Class { |
| 29 | + TypeAbstractRequestMatcherRegistry() { |
| 30 | + this |
| 31 | + .hasQualifiedName("org.springframework.security.config.annotation.web", |
| 32 | + "AbstractRequestMatcherRegistry<AuthorizedUrl<>>") |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * The class |
| 38 | + * `org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.EndpointRequestMatcher`. |
| 39 | + */ |
| 40 | +class TypeEndpointRequestMatcher extends Class { |
| 41 | + TypeEndpointRequestMatcher() { |
| 42 | + this |
| 43 | + .hasQualifiedName("org.springframework.boot.actuate.autoconfigure.security.servlet", |
| 44 | + "EndpointRequest$EndpointRequestMatcher") |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * A call to `HttpSecurity.requestMatcher` method with argument of type |
| 50 | + * `EndpointRequestMatcher`. |
| 51 | + */ |
| 52 | +class RequestMatcherCall extends MethodAccess { |
| 53 | + RequestMatcherCall() { |
| 54 | + getMethod().hasName("requestMatcher") and |
| 55 | + getMethod().getDeclaringType() instanceof TypeHttpSecurity and |
| 56 | + getArgument(0).getType() instanceof TypeEndpointRequestMatcher |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * A call to `HttpSecurity.requestMatchers` method with lambda argument resolving to |
| 62 | + * `EndpointRequestMatcher` type. |
| 63 | + */ |
| 64 | +class RequestMatchersCall extends MethodAccess { |
| 65 | + RequestMatchersCall() { |
| 66 | + getMethod().hasName("requestMatchers") and |
| 67 | + getMethod().getDeclaringType() instanceof TypeHttpSecurity and |
| 68 | + getArgument(0).(LambdaExpr).getExprBody().getType() instanceof TypeEndpointRequestMatcher |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/** A call to `HttpSecurity.authorizeRequests` method. */ |
| 73 | +class AuthorizeRequestsCall extends MethodAccess { |
| 74 | + AuthorizeRequestsCall() { |
| 75 | + getMethod().hasName("authorizeRequests") and |
| 76 | + getMethod().getDeclaringType() instanceof TypeHttpSecurity |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +/** A call to `AuthorizedUrl.permitAll` method. */ |
| 81 | +class PermitAllCall extends MethodAccess { |
| 82 | + PermitAllCall() { |
| 83 | + getMethod().hasName("permitAll") and |
| 84 | + getMethod().getDeclaringType() instanceof TypeAuthorizedUrl |
| 85 | + } |
| 86 | + |
| 87 | + /** Holds if `permitAll` is called on request(s) mapped to actuator endpoint(s). */ |
| 88 | + predicate permitsSpringBootActuators() { |
| 89 | + exists( |
| 90 | + RequestMatcherCall requestMatcherCall, RequestMatchersCall requestMatchersCall, |
| 91 | + RegistryRequestMatchersCall registryRequestMatchersCall, |
| 92 | + AuthorizeRequestsCall authorizeRequestsCall, AnyRequestCall anyRequestCall |
| 93 | + | |
| 94 | + // .requestMatcher(EndpointRequest).authorizeRequests([...]).[...] |
| 95 | + authorizeRequestsCall.getQualifier() = requestMatcherCall |
| 96 | + or |
| 97 | + // .requestMatchers(matcher -> EndpointRequest).authorizeRequests([...]).[...] |
| 98 | + authorizeRequestsCall.getQualifier() = requestMatchersCall |
| 99 | + or |
| 100 | + // http.authorizeRequests([...]).[...] |
| 101 | + authorizeRequestsCall.getQualifier() instanceof VarAccess |
| 102 | + | |
| 103 | + // [...].authorizeRequests(r -> r.anyRequest().permitAll()) or |
| 104 | + // [...].authorizeRequests(r -> r.requestMatchers(EndpointRequest).permitAll()) |
| 105 | + authorizeRequestsCall.getArgument(0).(LambdaExpr).getExprBody() = this and |
| 106 | + ( |
| 107 | + this.getQualifier() = anyRequestCall or |
| 108 | + this.getQualifier() = registryRequestMatchersCall |
| 109 | + ) |
| 110 | + or |
| 111 | + // [...].authorizeRequests().requestMatchers(EndpointRequest).permitAll() or |
| 112 | + // [...].authorizeRequests().anyRequest().permitAll() |
| 113 | + authorizeRequestsCall.getNumArgument() = 0 and |
| 114 | + ( |
| 115 | + registryRequestMatchersCall.getQualifier() = authorizeRequestsCall and |
| 116 | + this.getQualifier() = registryRequestMatchersCall |
| 117 | + ) |
| 118 | + or |
| 119 | + anyRequestCall.getQualifier() = authorizeRequestsCall and |
| 120 | + this.getQualifier() = anyRequestCall |
| 121 | + ) |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +/** A call to `AbstractRequestMatcherRegistry.anyRequest` method. */ |
| 126 | +class AnyRequestCall extends MethodAccess { |
| 127 | + AnyRequestCall() { |
| 128 | + getMethod().hasName("anyRequest") and |
| 129 | + getMethod().getDeclaringType() instanceof TypeAbstractRequestMatcherRegistry |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +/** |
| 134 | + * A call to `AbstractRequestMatcherRegistry.requestMatchers` method with an argument of type |
| 135 | + * `EndpointRequestMatcher`. |
| 136 | + */ |
| 137 | +class RegistryRequestMatchersCall extends MethodAccess { |
| 138 | + RegistryRequestMatchersCall() { |
| 139 | + getMethod().hasName("requestMatchers") and |
| 140 | + getMethod().getDeclaringType() instanceof TypeAbstractRequestMatcherRegistry and |
| 141 | + getAnArgument().getType() instanceof TypeEndpointRequestMatcher |
| 142 | + } |
| 143 | +} |
0 commit comments