Skip to content

Java: replace the dead String.valueOf(CharSequence) summary with a synthetic callable - #22315

Merged
hvitved merged 4 commits into
mainfrom
copilot/fix-valueof-call-site-issue
Aug 13, 2026
Merged

Java: replace the dead String.valueOf(CharSequence) summary with a synthetic callable#22315
hvitved merged 4 commits into
mainfrom
copilot/fix-valueof-call-site-issue

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

java.lang.String has no valueOf(CharSequence) overload — string- and CharSequence-typed arguments compile to valueOf(Object), which is modelled as neutral. The summary row therefore matched no call site, leaving no propagating valueOf model for string-typed arguments:

String data = req.getParameter("cmd");  // source
String s1 = String.valueOf(data);       // taint lost: resolves to valueOf(Object)
Runtime.getRuntime().exec(s1);          // sink, not reported

Changes

  • java/ql/lib/ext/java.lang.model.yml: removed the ["java.lang", "String", False, "valueOf", "(CharSequence)", ...] row, which matched nothing.
  • java/ql/lib/semmle/code/java/frameworks/Strings.qll (new): a SyntheticCallable that propagates taint Argument[0]ReturnValue for String.valueOf(Object) calls whose argument's static type is a CharSequence (String, CharSequence, StringBuilder, …), where the call is equivalent to the documented CharSequence.toString(). Registered in the SyntheticCallables module in FlowSummary.qll.
  • The valueOf(Object) neutral model is kept, so arguments of arbitrary types — whose toString() may not expose tainted state — remain unaffected.
  • Tests: java/ql/test/library-tests/dataflow/string-valueof covers String, CharSequence, StringBuilder, char[] and char arguments (flow expected) and an Object-typed argument (no flow expected). Change note added.

Copilot AI and others added 2 commits August 11, 2026 08:24
…a synthetic callable for valueOf(Object) on CharSequence arguments

Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix valueOf method call site issue for string arguments Java: replace the dead String.valueOf(CharSequence) summary with a synthetic callable Aug 11, 2026
Copilot AI requested a review from hvitved August 11, 2026 08:25

@hvitved hvitved left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fix the test failure reported by CI.

@hvitved
hvitved marked this pull request as ready for review August 12, 2026 07:41
@hvitved
hvitved requested a review from a team as a code owner August 12, 2026 07:41
Copilot AI balanced review requested due to automatic review settings August 12, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Replaces an ineffective String.valueOf(CharSequence) model with conditional propagation for String.valueOf(Object) calls receiving CharSequence values.

Changes:

  • Adds and registers the synthetic callable.
  • Removes the nonexistent-overload model.
  • Adds regression tests, generated expectations, and a change note.
Show a summary per file
File Description
java/ql/test/utils/modelgenerator/dataflow/p/Joiner.java Updates generated summary expectations.
java/ql/test/library-tests/dataflow/string-valueof/test.ql Configures the flow test.
java/ql/test/library-tests/dataflow/string-valueof/test.expected Records expected models and flow edges.
java/ql/test/library-tests/dataflow/string-valueof/A.java Covers propagating and non-propagating argument types.
java/ql/lib/semmle/code/java/frameworks/Strings.qll Defines conditional valueOf(Object) propagation.
java/ql/lib/semmle/code/java/dataflow/FlowSummary.qll Registers the synthetic callable.
java/ql/lib/ext/java.lang.model.yml Removes the dead summary row.
java/ql/lib/change-notes/2026-08-11-string-valueof-charsequence.md Documents the analysis improvement.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 8/8 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@owen-mc

owen-mc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor
Rerun has been triggered: 2 restarted 🚀

@owen-mc owen-mc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I didn't know about Synthetic Callable before. I've restarted the CI runs which failed - I suspect they are unrelated. If they pass then you can merge.

@owen-mc

owen-mc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

I've started DCA, so we should also wait for that to finish and check the results.

@hvitved

hvitved commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

I've started DCA, so we should also wait for that to finish and check the results.

Thanks, but I already did one.

@owen-mc

owen-mc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Ah yes, I missed that. The times seems okay (within the margins of error for normal java behaviour). And hive seems to lose one concatenated-sql alert and gain two sql-injection alerts. Did you investigate the alert changes?

@hvitved

hvitved commented Aug 13, 2026 via email

Copy link
Copy Markdown
Contributor

@owen-mc

owen-mc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Cool. Well, it looks good to me and CI is passing. The only thing stopping it being merged is your review.

@hvitved
hvitved merged commit 9d247d6 into main Aug 13, 2026
25 checks passed
@hvitved
hvitved deleted the copilot/fix-valueof-call-site-issue branch August 13, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.String: the valueOf(CharSequence) summary row matches no call site, leaving no propagating valueOf model for a string-typed argument

4 participants