8000 Java: Promote Spring Boot Actuators query from experimental by jcogs33 · Pull Request #18793 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

Java: Promote Spring Boot Actuators query from experimental #18793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Java: some refactoring
  • Loading branch information
Jami Cogswell authored and Jami Cogswell committed Feb 24, 2025
commit 6fe7c7a2334dff8db2df115aa02751cf399f3645
10000
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class TypeAbstractRequestMatcherRegistry extends Class {
}

/**
* A call to `HttpSecurity.authorizeRequests` method.
* A call to the `HttpSecurity.authorizeRequests` method.
*
* Note: this API is deprecated and scheduled for removal
* Note: this method is deprecated and scheduled for removal
* in Spring Security 7.0.
*/
class AuthorizeRequestsCall extends MethodCall {
Expand All @@ -53,9 +53,9 @@ class AuthorizeRequestsCall extends MethodCall {
}

/**
* A call to `HttpSecurity.authorizeHttpRequests` method.
* A call to the `HttpSecurity.authorizeHttpRequests` method.
*
* Note: the no-argument version of this API is deprecated
* Note: the no-argument version of this method is deprecated
* and scheduled for removal in Spring Security 7.0.
*/
class AuthorizeHttpRequestsCall extends MethodCall {
Expand All @@ -65,15 +65,57 @@ class AuthorizeHttpRequestsCall extends MethodCall {
}
}

/** A call to `AuthorizedUrl.permitAll` method. */
/**
* A call to the `HttpSecurity.requestMatcher` method.
*
* Note: this method was removed in Spring Security 6.0.
* It was replaced by `securityMatcher`.
*/
class RequestMatcherCall extends MethodCall {
RequestMatcherCall() {
this.getMethod().hasName("requestMatcher") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
}
}

/**
* A call to the `HttpSecurity.requestMatchers` method.
*
* Note: this method was removed in Spring Security 6.0.
* It was replaced by `securityMatchers`.
*/
class RequestMatchersCall extends MethodCall {
RequestMatchersCall() {
this.getMethod().hasName("requestMatchers") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
}
}

/** A call to the `HttpSecurity.securityMatcher` method. */
class SecurityMatcherCall extends MethodCall {
SecurityMatcherCall() {
this.getMethod().hasName("securityMatcher") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
}
}

/** A call to the `HttpSecurity.securityMatchers` method. */
class SecurityMatchersCall extends MethodCall {
SecurityMatchersCall() {
this.getMethod().hasName("securityMatchers") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
}
}

/** A call to the `AuthorizedUrl.permitAll` method. */
class PermitAllCall extends MethodCall {
PermitAllCall() {
this.getMethod().hasName("permitAll") and
this.getMethod().getDeclaringType() instanceof TypeAuthorizedUrl
}
}

/** A call to `AbstractRequestMatcherRegistry.anyRequest` method. */
/** A call to the `AbstractRequestMatcherRegistry.anyRequest` method. */
class AnyRequestCall extends MethodCall {
AnyRequestCall() {
this.getMethod().hasName("anyRequest") and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ private import semmle.code.java.frameworks.spring.SpringSecurity
private import semmle.code.java.frameworks.spring.SpringBoot

/**
* A call to `HttpSecurity.requestMatcher` method with argument
* A call to an `HttpSecurity` matcher method with argument
* `EndpointRequest.toAnyEndpoint()`.
*/
private class RequestMatcherCall extends MethodCall {
RequestMatcherCall() {
this.getMethod().hasName("requestMatcher") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity and
private class HttpSecurityMatcherCall extends MethodCall {
HttpSecurityMatcherCall() {
(
this instanceof RequestMatcherCall or
this instanceof SecurityMatcherCall
) and
this.getArgument(0) instanceof ToAnyEndpointCall
}
}

/**
* A call to `HttpSecurity.requestMatchers` method with lambda argument
* `EndpointRequest.toAnyEndpoint()`.
* A call to an `HttpSecurity` matchers method with lambda
* argument `EndpointRequest.toAnyEndpoint()`.
*/
private class RequestMatchersCall extends MethodCall {
RequestMatchersCall() {
this.getMethod().hasName("requestMatchers") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity and
private class HttpSecurityMatchersCall extends MethodCall {
HttpSecurityMatchersCall() {
(
this instanceof RequestMatchersCall or
this instanceof SecurityMatchersCall
) and
this.getArgument(0).(LambdaExpr).getExprBody() instanceof ToAnyEndpointCall
}
}

/**
* A call to `AbstractRequestMatcherRegistry.requestMatchers` method with an argument
* `RequestMatcher.toAnyEndpoint()`.
* A call to an `AbstractRequestMatcherRegistry.requestMatchers` method with
* argument `EndpointRequest.toAnyEndpoint()`.
*/
private class RegistryRequestMatchersCall extends MethodCall {
RegistryRequestMatchersCall() {
Expand All @@ -40,71 +44,22 @@ private class RegistryRequestMatchersCall extends MethodCall {
}
}

/**
* A call to `HttpSecurity.securityMatcher` method with argument
* `EndpointRequest.toAnyEndpoint()`.
*/
private class SecurityMatcherCall extends MethodCall {
SecurityMatcherCall() {
this.getMethod().hasName("securityMatcher") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity and
this.getArgument(0) instanceof ToAnyEndpointCall
}
}

/**
* A call to `HttpSecurity.securityMatchers` method with lambda argument
* `EndpointRequest.toAnyEndpoint()`.
*/
private class SecurityMatchersCall extends MethodCall {
SecurityMatchersCall() {
this.getMethod().hasName("securityMatchers") and
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity and
this.getArgument(0).(LambdaExpr).getExprBody() instanceof ToAnyEndpointCall
}
}

/**
* A call to a method that authorizes requests, e.g. `authorizeRequests` or
* `authorizeHttpRequests`.
*/
/** A call to an `HttpSecurity` method that authorizes requests. */
private class AuthorizeCall extends MethodCall {
AuthorizeCall() {
this instanceof AuthorizeRequestsCall or
this instanceof AuthorizeHttpRequestsCall
}
}

/**
* A call to a matcher method with argument
* `EndpointRequest.toAnyEndpoint()`.
*/
private class MatcherCall extends MethodCall {
MatcherCall() {
this instanceof RequestMatcherCall or
this instanceof SecurityMatcherCall
}
}

/**
* A call to a matchers method with argument
* `EndpointRequest.toAnyEndpoint()`.
*/
private class MatchersCall extends MethodCall {
MatchersCall() {
this instanceof RequestMatchersCall or
this instanceof SecurityMatchersCall
}
}

/** Holds if `permitAllCall` is called on request(s) mapped to actuator endpoint(s). */
predicate permitsSpringBootActuators(PermitAllCall permitAllCall) {
exists(AuthorizeCall authorizeCall |
// .requestMatcher(EndpointRequest).authorizeRequests([...]).[...]
authorizeCall.getQualifier() instanceof MatcherCall
authorizeCall.getQualifier() instanceof HttpSecurityMatcherCall
or
// .requestMatchers(matcher -> EndpointRequest).authorizeRequests([...]).[...]
authorizeCall.getQualifier() instanceof MatchersCall
authorizeCall.getQualifier() instanceof HttpSecurityMatchersCall
|
// [...].authorizeRequests(r -> r.anyRequest().permitAll()) or
// [...].authorizeRequests(r -> r.requestMatchers(EndpointRequest).permitAll())
Expand Down Expand Up @@ -143,7 +98,7 @@ predicate permitsSpringBootActuators(PermitAllCall permitAllCall) {
permitAllCall.getQualifier() = registryRequestMatchersCall
)
or
exists(Variable v, MatcherCall matcherCall |
exists(Variable v, HttpSecurityMatcherCall matcherCall |
// http.securityMatch 45F3 er(EndpointRequest.toAnyEndpoint());
// http.authorizeRequests([...].permitAll())
v.getAnAccess() = authorizeCall.getQualifier() and
Expand Down
0