Skip to content

Fix SpringRequestMappingMethod URL Extraction: Use getAStringArrayValue Instead of getValue #19512

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sentient0being
Copy link

Previously, the SpringRequestMappingMethod class in CodeQL used the getValue or getStringValue predicate to extract the "value" attribute from Spring's @RequestMapping and related annotations. However, in Spring, the "value" and "path" attributes are defined as String[] (string arrays), not single strings. This caused issues where URLs could not be extracted if they were specified as arrays.

This PR updates the relevant logic to use getAStringArrayValue, which correctly handles array-typed annotation elements and ensures all specified URLs are extracted, regardless of whether they are provided as single values or arrays. This change improves the accuracy and reliability of Spring controller route extraction in CodeQL queries.

spring-web-5.2.8.RELEASE
org.springframework.web.bind.annotation.RequestMapping
image
or
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java

@Copilot Copilot AI review requested due to automatic review settings May 17, 2025 11:57
@sentient0being sentient0being requested a review from a team as a code owner May 17, 2025 11:57
@github-actions github-actions bot added the Java label May 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue with URL extraction from Spring’s @RequestMapping annotations by switching from getStringValue to getAStringArrayValue, ensuring both single and array-typed values are correctly handled.

  • Introduces a new method getArrayValue to extract array-based string values.
  • Enhances the accuracy of URL extraction in CodeQL queries for Spring controllers.
Comments suppressed due to low confidence (1)

java/ql/lib/semmle/code/java/frameworks/spring/SpringController.qll:162

  • The method getArrayValue is declared to return a single string despite extracting an array value. Confirm whether the intended design is to merge multiple values into one string, and consider adjusting the return type for clarity if necessary.
string getArrayValue() { result = requestMappingAnnotation.getAStringArrayValue("value") }

@@ -156,6 +156,10 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
/** Gets the "value" @RequestMapping annotation value, if present. */
string getValue() { result = requestMappingAnnotation.getStringValue("value") }



/** Gets the "value" @RequestMapping annotation array string value, if present. */
Copy link
Preview

Copilot AI May 17, 2025

Choose a reason for hiding this comment

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

Clarify in the documentation how getArrayValue behaves when multiple URL strings are present in the annotation, e.g., whether they are concatenated or handled in some other way.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant