Skip to content

Java: Add CodeQL support and tests for Micronaut framework - #5

Open
anurag6569201 wants to merge 1 commit into
qa/agent-github-codeql/pr-05-21387/basefrom
qa/agent-github-codeql/pr-05-21387/head
Open

anurag6569201 wants to merge 1 commit into
qa/agent-github-codeql/pr-05-21387/basefrom
qa/agent-github-codeql/pr-05-21387/head

Conversation

@anurag6569201

Copy link
Copy Markdown

This pull request adds CodeQL modeling for the Micronaut Java framework, covering HTTP controllers, WebSocket endpoints, configuration injection, security annotations, and relevant sources and sinks. The changes integrate Micronaut-specific classes and methods into the CodeQL dataflow architecture, enabling taint tracking and threat modeling for user input, configuration, and HTTP/WebSocket requests. Test cases are included to verify the new models.

Micronaut framework modeling:

  • Added overlays for Micronaut HTTP controllers, request mapping methods, input parameters, error handlers, and request beans in MicronautController.qll, enabling detection and classification of user-controlled input sources.
  • Introduced overlays for Micronaut WebSocket endpoints, message handlers, and user input parameters in MicronautWebSocket.qll.
  • Added overlays for Micronaut configuration injection via @Value and @Property annotations, modeling fields and parameters as local user input in MicronautConfig.qll.
  • Added overlays for Micronaut Data repositories and query annotations in MicronautData.qll.
  • Added overlays for Micronaut Security, modeling @Secured annotations for classes and methods in MicronautSecurity.qll.

Dataflow source and sink integration:

  • Extended FlowSources.qll to include Micronaut HTTP input parameters, WebSocket parameters, configuration fields/parameters, and error handler parameters as sources, using the new overlays. [1] [2]
  • Added source, summary, and sink models for Micronaut HTTP, multipart, and client APIs in .model.yml files, covering taint propagation and SSRF, response splitting, and URL redirection sinks. [1] [2] [3]

Test coverage:

  • Added test cases for Micronaut controller input sources and error handlers in MicronautControllerTest.java.
  • Added test cases for Micronaut configuration injection sources in MicronautConfigTest.java.

Source merge-base: d045392042b2233c7cefa615c3cb5814a201c37b
Source head: 16e9b22b333cdc4cef4244baa8d162da55fc22eb

@shipwright-agent

Copy link
Copy Markdown

⛔ Shipwright · Blocked

Recommendation: do not merge PR #5 · Tier T3
Checks: 0 total · 0 needing attention

Next step: resolve the blocking findings before merge.

Findings (8)

  • CRITICAL The exclusion predicate uses getAnAncestor() on RefType, which only checks supertypes, not implemented interfaces. · java/ql/lib/semmle/code/java/frameworks/micronaut/MicronautController.qll:88
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • CRITICAL MicronautRequestMappingParameter.isTaintedInput defaults every unannotated controller method parameter to tainted unless it matches a narrow exclusion list. · java/ql/lib/semmle/code/java/frameworks/micronaut/MicronautController.qll:100
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • CRITICAL MicronautWebSocketParameter treats every parameter of OnOpen, OnMessage, and OnClose handlers as remote taint except CloseReason and WebSocketSession. · java/ql/lib/semmle/code/java/frameworks/micronaut/MicronautWebSocket.qll:44
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The new Micronaut framework modules are declared as overlay[local?] modules. · java/ql/lib/semmle/code/java/frameworks/micronaut/MicronautController.qll:4
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The source model marks HttpRequest.getContentLength() and getMethodName() as remote taint sources. · java/ql/lib/ext/io.micronaut.http.model.yml:6
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The summary model for UriBuilder.expand(Map) propagates taint from Argument[0].MapValue to ReturnValue, but the stub and real Micronaut API use Map<String, ? · java/ql/lib/ext/io.micronaut.http.uri.model.yml:5
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The HTTP client sink model marks only Argument[0] of exchange/retrieve as request-forgery. · java/ql/lib/ext/io.micronaut.http.client.model.yml:8
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • LOW The change note claims modeling for 'data access' and 'security annotations', but the added MicronautData.qll and MicronautSecurity.qll only define annotation/class recognition wit · java/ql/lib/change-notes/2026-02-27-micronaut.md:4
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Fireworks usage: 54,562 input · 1,033 output · 55,595 total tokens · $0.0127 · 18s · 0 fix iteration(s)

Open the Shipwright check for full evidence and the audit bundle. Use /shipwright rerun to verify again.

/** Holds if the parameter should not be considered a direct source of taint. */
predicate isNotDirectlyTaintedInput() {
this.getType().(RefType).getAnAncestor().hasQualifiedName("io.micronaut.http", "HttpResponse")
or

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · CRITICAL

The exclusion predicate uses getAnAncestor() on RefType, which only checks supertypes, not implemented interfaces.

Impact: The exclusion predicate uses getAnAncestor() on RefType, which only checks supertypes, not implemented interfaces. Parameters typed as java.security.Principal, java.util.Locale, java.io.Reader, or java.io.InputStream via interface types will not be excluded and will be incorrectly tainted, causing false positives in every query consuming FlowSources.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

this.getType().(RefType).getAnAncestor() instanceof TypeInputStream
or
this.getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "Reader")
or

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · CRITICAL

MicronautRequestMappingParameter.isTaintedInput defaults every unannotated controller method parameter to tainted unless it matches a narrow exclusion list.

Impact: MicronautRequestMappingParameter.isTaintedInput defaults every unannotated controller method parameter to tainted unless it matches a narrow exclusion list. Framework-injected types not in the exclusion list (e.g., Authentication, custom Principal subclasses, BindingResult, HttpSession, reactive contexts) will be treated as remote user input, producing false-positive taint flows and potentially masking real findings…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

}

/** A parameter of a Micronaut WebSocket message handler that receives user-controlled data. */
class MicronautWebSocketParameter extends Parameter {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · CRITICAL

MicronautWebSocketParameter treats every parameter of OnOpen, OnMessage, and OnClose handlers as remote taint except CloseReason and WebSocketSession.

Impact: MicronautWebSocketParameter treats every parameter of OnOpen, OnMessage, and OnClose handlers as remote taint except CloseReason and WebSocketSession. OnOpen handlers commonly receive framework-injected WebSocketSession, HttpRequest, or Principal parameters; OnClose handlers receive CloseReason. Any other framework type (e.g., WebSocketBroadcaster, WebSocketSession subclasses) becomes a false taint source, and OnOpe…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

/**
* Provides classes for identifying Micronaut HTTP controllers and their request handling methods.
*/
overlay[local?]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The new Micronaut framework modules are declared as overlay[local?] modules.

Impact: The new Micronaut framework modules are declared as overlay[local?] modules. If this syntax is not supported by the target CodeQL distribution or is misconfigured, the modules may be silently ignored or fail to compile, leaving the advertised Micronaut modeling inactive without any test or CI evidence in the provided check index.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

pack: codeql/java-all
extensible: sourceModel
data:
- ["io.micronaut.http", "HttpRequest", True, "getBody", "", "", "ReturnValue", "remote", "manual"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The source model marks HttpRequest.getContentLength() and getMethodName() as remote taint sources.

Impact: The source model marks HttpRequest.getContentLength() and getMethodName() as remote taint sources. These return a long and a String derived from request metadata, not attacker-controlled content. Treating them as tainted will create false flows into numeric and string sinks and dilute query precision.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

- addsTo:
pack: codeql/java-all
extensible: summaryModel
data:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The summary model for UriBuilder.expand(Map) propagates taint from Argument[0].MapValue to ReturnValue, but the stub and real Micronaut API use Map<String, ?

Impact: The summary model for UriBuilder.expand(Map) propagates taint from Argument[0].MapValue to ReturnValue, but the stub and real Micronaut API use Map<String, ? super Object>. If the CodeQL model does not resolve MapValue for wildcard-typed maps, the taint propagation will silently fail, causing missed flows through URI template expansion.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

data:
- ["io.micronaut.http.client", "BlockingHttpClient", True, "exchange", "(HttpRequest)", "", "Argument[0]", "request-forgery", "manual"]
- ["io.micronaut.http.client", "BlockingHttpClient", True, "exchange", "(HttpRequest,Argument)", "", "Argument[0]", "request-forgery", "manual"]
- ["io.micronaut.http.client", "BlockingHttpClient", True, "exchange", "(HttpRequest,Argument,Argument)", "", "Argument[0]", "request-forgery", "manual"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The HTTP client sink model marks only Argument[0] of exchange/retrieve as request-forgery.

Impact: The HTTP client sink model marks only Argument[0] of exchange/retrieve as request-forgery. For overloads taking a String URI, the URI is the request target and should be modeled, but the sink kind request-forgery on a String argument may not match the expected taint source for URL manipulation queries, potentially missing SSRF-like flows through user-controlled URI strings.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

---
category: minorAnalysis
---
* Added modeling for the Micronaut framework, including HTTP controllers, WebSocket endpoints, configuration injection, data access, security annotations, and HTTP client sinks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · LOW

The change note claims modeling for 'data access' and 'security annotations', but the added MicronautData.qll and MicronautSecurity.qll only define annotation/class recognition wit

Impact: The change note claims modeling for 'data access' and 'security annotations', but the added MicronautData.qll and MicronautSecurity.qll only define annotation/class recognition with no dataflow integration or query behavior. A maintainer reading the change note will expect functional modeling that does not exist yet.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant