Skip to content

Commit

Permalink
HHH-14077 CVE-2019-14900 SQL injection issue using JPA Criteria API
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 authored and sebersole committed Jun 23, 2020
1 parent d9a33bf commit eebf01f
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @author Steve Ebersole
*/
public class JdbcLiteralFormatterCharacterData extends BasicJdbcLiteralFormatter {
public static final String NATIONALIZED_PREFIX = "n";

private final boolean isNationalized;

public JdbcLiteralFormatterCharacterData(JavaTypeDescriptor javaTypeDescriptor) {
Expand All @@ -34,12 +36,13 @@ public JdbcLiteralFormatterCharacterData(JavaTypeDescriptor javaTypeDescriptor,
public String toJdbcLiteral(Object value, Dialect dialect, SharedSessionContractImplementor session) {
final String literalValue = unwrap( value, String.class, session );

final String inlineLiteral = dialect.inlineLiteral( literalValue );

if ( isNationalized ) {
// is there a standardized form for n-string literals? This is the SQL Server syntax for sure
return String.format( Locale.ROOT, "n'%s'", literalValue );
}
else {
return String.format( Locale.ROOT, "'%s'", literalValue );
return NATIONALIZED_PREFIX.concat( inlineLiteral );
}

return inlineLiteral;
}
}

0 comments on commit eebf01f

Please sign in to comment.