Skip to content

Commit bda04f0

Browse files
committed
Use Locale.ROOT for locale neutral, case insensitive comparisons
This addresses CVE-2024-38820
1 parent 8a44eaa commit bda04f0

File tree

23 files changed

+76
-48
lines changed

23 files changed

+76
-48
lines changed

spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.Comparator;
2121
import java.util.List;
22+
import java.util.Locale;
2223

2324
import org.apache.commons.logging.Log;
2425
import org.apache.commons.logging.LogFactory;
@@ -77,8 +78,8 @@ public int compare(T o1, T o2) {
7778
Object v1 = getPropertyValue(o1);
7879
Object v2 = getPropertyValue(o2);
7980
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String) && (v2 instanceof String)) {
80-
v1 = ((String) v1).toLowerCase();
81-
v2 = ((String) v2).toLowerCase();
81+
v1 = ((String) v1).toLowerCase(Locale.ROOT);
82+
v2 = ((String) v2).toLowerCase(Locale.ROOT);
8283
}
8384

8485
int result;

spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.sql.Connection;
2020
import java.sql.DatabaseMetaData;
2121
import java.sql.SQLException;
22+
import java.util.Locale;
2223

2324
import javax.sql.DataSource;
2425

@@ -155,7 +156,7 @@ public void initialize() {
155156
String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource,
156157
DatabaseMetaData::getDatabaseProductName);
157158
productName = JdbcUtils.commonDatabaseName(productName);
158-
if (productName != null && productName.toLowerCase().contains("hsql")) {
159+
if (productName != null && productName.toLowerCase(Locale.ROOT).contains("hsql")) {
159160
setUseDBLocks(false);
160161
setLockHandler(new SimpleSemaphore());
161162
}

spring-context/src/main/java/org/springframework/format/datetime/standard/MonthFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MonthFormatter implements Formatter<Month> {
3434

3535
@Override
3636
public Month parse(String text, Locale locale) throws ParseException {
37-
return Month.valueOf(text.toUpperCase());
37+
return Month.valueOf(text.toUpperCase(Locale.ROOT));
3838
}
3939

4040
@Override

spring-context/src/main/java/org/springframework/scheduling/support/CronField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.temporal.ChronoUnit;
2222
import java.time.temporal.Temporal;
2323
import java.time.temporal.ValueRange;
24+
import java.util.Locale;
2425
import java.util.function.BiFunction;
2526

2627
import org.springframework.lang.Nullable;
@@ -143,7 +144,7 @@ private static CronField parseList(String value, Type type, BiFunction<String, T
143144
}
144145

145146
private static String replaceOrdinals(String value, String[] list) {
146-
value = value.toUpperCase();
147+
value = value.toUpperCase(Locale.ROOT);
147148
for (int i = 0; i < list.length; i++) {
148149
String replacement = Integer.toString(i + 1);
149150
value = StringUtils.replace(value, list[i], replacement);

spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Date;
2424
import java.util.GregorianCalendar;
2525
import java.util.List;
26+
import java.util.Locale;
2627
import java.util.TimeZone;
2728

2829
import org.springframework.lang.Nullable;
@@ -305,8 +306,8 @@ private void doParse(String[] fields) {
305306
private String replaceOrdinals(String value, String commaSeparatedList) {
306307
String[] list = StringUtils.commaDelimitedListToStringArray(commaSeparatedList);
307308
for (int i = 0; i < list.length; i++) {
308-
String item = list[i].toUpperCase();
309-
value = StringUtils.replace(value.toUpperCase(), item, "" + i);
309+
String item = list[i].toUpperCase(Locale.ROOT);
310+
value = StringUtils.replace(value.toUpperCase(Locale.ROOT), item, "" + i);
310311
}
311312
return value;
312313
}

spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.core.convert.support;
1818

1919
import java.util.HashSet;
20+
import java.util.Locale;
2021
import java.util.Set;
2122

2223
import org.springframework.core.convert.converter.Converter;
@@ -55,7 +56,7 @@ public Boolean convert(String source) {
5556
if (value.isEmpty()) {
5657
return null;
5758
}
58-
value = value.toLowerCase();
59+
value = value.toLowerCase(Locale.ROOT);
5960
if (trueValues.contains(value)) {
6061
return Boolean.TRUE;
6162
}

spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.env;
1818

19+
import java.util.Locale;
1920
import java.util.Map;
2021

2122
import org.springframework.lang.Nullable;
@@ -109,7 +110,7 @@ protected final String resolvePropertyName(String name) {
109110
if (resolvedName != null) {
110111
return resolvedName;
111112
}
112-
String uppercasedName = name.toUpperCase();
113+
String uppercasedName = name.toUpperCase(Locale.ROOT);
113114
if (!name.equals(uppercasedName)) {
114115
resolvedName = checkPropertyName(uppercasedName);
115116
if (resolvedName != null) {

spring-core/src/main/java/org/springframework/util/ResourceUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.net.URISyntaxException;
2424
import java.net.URL;
2525
import java.net.URLConnection;
26+
import java.util.Locale;
2627

2728
import org.springframework.lang.Nullable;
2829

@@ -295,7 +296,7 @@ public static boolean isJarURL(URL url) {
295296
*/
296297
public static boolean isJarFileURL(URL url) {
297298
return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
298-
url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
299+
url.getPath().toLowerCase(Locale.ROOT).endsWith(JAR_FILE_EXTENSION));
299300
}
300301

301302
/**

spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package org.springframework.expression.spel;
1818

19+
import java.util.Locale;
20+
1921
import org.springframework.core.SpringProperties;
2022
import org.springframework.lang.Nullable;
2123

24+
25+
2226
/**
2327
* Configuration object for the SpEL expression parser.
2428
*
@@ -45,7 +49,7 @@ public class SpelParserConfiguration {
4549
static {
4650
String compilerMode = SpringProperties.getProperty(SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME);
4751
defaultCompilerMode = (compilerMode != null ?
48-
SpelCompilerMode.valueOf(compilerMode.toUpperCase()) : SpelCompilerMode.OFF);
52+
SpelCompilerMode.valueOf(compilerMode.toUpperCase(Locale.ROOT)) : SpelCompilerMode.OFF);
4953
}
5054

5155

spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.expression.spel.ast;
1818

1919
import java.lang.reflect.Array;
20+
import java.util.Locale;
2021

2122
import org.springframework.asm.MethodVisitor;
2223
import org.springframework.asm.Type;
@@ -57,7 +58,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
5758
String typeName = (String) this.children[0].getValueInternal(state).getValue();
5859
Assert.state(typeName != null, "No type name");
5960
if (!typeName.contains(".") && Character.isLowerCase(typeName.charAt(0))) {
60-
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase());
61+
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase(Locale.ROOT));
6162
if (tc != TypeCode.OBJECT) {
6263
// It is a primitive type
6364
Class<?> clazz = makeArrayIfNecessary(tc.getType());

0 commit comments

Comments
 (0)