Skip to content

validate language subtag in GwtLocale fromString - #10368

Open
Samin061 wants to merge 1 commit into
gwtproject:mainfrom
Samin061:gwtlocale-language-validation
Open

validate language subtag in GwtLocale fromString#10368
Samin061 wants to merge 1 commit into
gwtproject:mainfrom
Samin061:gwtlocale-language-validation

Conversation

@Samin061

Copy link
Copy Markdown

On the server the active locale is read straight from the request by GwtServletBase.getGwtLocale (the locale query parameter or a cookie) and stored as the thread 'locale' property, and GwtLocaleFactoryImpl.fromString then parses that string into subtags. It checks the script, region and variant components against length and character rules but takes the primary language subtag as-is with only a lower-casing pass, and the code still carries a TODO to verify the language tag. Because the split only happens on '-' and '_', a value such as locale=java.lang.Runtime survives intact as the language, and LocalizableInstantiator concatenates that language into class names it passes to Class.forName().newInstance() when server code calls GWT.create on a Localizable, so '.', '$' and '/' can be smuggled into the reflective lookup. I came across it while tracing where the untrusted locale property finally lands. The fix validates the assembled language tag against the same BCP47 subtag shape the other components already require and throws IllegalArgumentException otherwise, kept inside fromString so every caller is covered without disturbing the parse flow. Existing locales, including extended-language and private-use forms like zh-cmn and x-foo123, are unaffected.

Comment thread user/src/com/google/gwt/i18n/server/GwtLocaleFactoryImpl.java Outdated
Reject any subtag that is not 1-8 alphanumeric characters at the point the
locale string is split. The split only breaks on '-'/'_', so characters like
'.', '$' or '/' otherwise survive in the primary language subtag, which flows
into class names resolved reflectively by LocalizableInstantiator when server
code calls GWT.create on a Localizable with an untrusted 'locale' property.
@Samin061
Samin061 force-pushed the gwtlocale-language-validation branch from e358fc9 to 91f2d59 Compare July 15, 2026 06:57
vjay82 pushed a commit to vjay82/gwt that referenced this pull request Jul 18, 2026
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.

2 participants