fix: avoid format strings in FrontendUtils.console - #25048
Open
hej090224 wants to merge 4 commits into
Open
Conversation
FrontendUtils.console() passed a caller-supplied format string to String.format(), which static analysis flags as CWE-134. The ANSI color constants (YELLOW, RED, GREEN, BRIGHT_BLUE) are changed to hold only the color escape prefix, a new ANSI_RESET constant holds the reset sequence, and console() now concatenates color, message and reset instead of formatting the message, so the text is always printed literally. Fixes vaadin#9263
|
|
hej090224
marked this pull request as ready for review
July 25, 2026 16:34
Collaborator
|
@hej090224 could you please sign the CLA? Otherwise we cannot proceed with this PR. |
Author
|
@mcollovati Apologies for the delayed response — I missed the CLA notification. I'll sign the CLA now via the link above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FrontendUtils.console()passed a caller-controlledformatparameterstraight into
String.format(), which static analysis tools flag asCWE-134 (uncontrolled format string), since the method's contract does not
guarantee the argument is a compile-time constant.
In the current codebase,
console()is only called with the ANSI colorconstants (
GREEN,RED) as the "format" argument. Those constants usedto be full
String.format()templates: an ANSI color escape prefix,followed by a
%soutlet for the message, followed by the ANSI resetescape. This PR removes the
String.format()call entirely: the colorconstants now hold only the ANSI escape prefix, a new
ANSI_RESETconstantholds the reset escape, and
console()builds the output via plain stringconcatenation (
ansiColor + message + ANSI_RESET). The message argument istherefore always printed literally and can never be interpreted as a format
string.
Changes
flow-server/.../internal/FrontendUtils.java:YELLOW,RED,GREEN,BRIGHT_BLUEno longer embed a%soutlet;they are now just the ANSI color escape prefix.
ANSI_RESETfor the shared reset escape sequence.console(String format, Object message)is nowconsole(String ansiColor, String message); it concatenates thecolor, message, and reset instead of calling
String.format().import static java.lang.String.format.flow-server/.../internal/FrontendUtilsTest.java(new): unit tests forconsole().No call sites needed changes: the only caller,
vaadin-dev-server/.../AbstractDevServerRunner.java, already passes plainStringconstants (START,SUCCEED_MSG,FAILED_MSG) as the message,so it compiles unchanged against the new signature and produces byte-for-byte
identical output (color prefix + message + reset).
Testing
New tests in
FrontendUtilsTestverify:ANSI_RESET%s,%c,%n, and a literal%are printedverbatim rather than being interpreted as format specifiers
Verification commands run locally:
mvn -pl flow-server -am -DskipITs -Dtest=FrontendUtilsTest -Dsurefire.failIfNoSpecifiedTests=false test→ 3/3 passedmvn -pl vaadin-dev-server -am -DskipITs -DskipTests install→ BUILD SUCCESS (confirms the only caller module still compiles against the new signature)mvn -pl flow-server spotless:check→ BUILD SUCCESS (afterspotless:apply)mvn -pl flow-server checkstyle:check→ fails, but with a pre-existing, unrelated parser error inflow-server/.../signals/shared/impl/MutableTreeRevision.java(a record pattern ininstanceofthat the bundled checkstyle grammar can't parse); this file is untouched by this PR and the failure reproduces onupstream/mainwithout this change.Fixes #9263