Issues
- Make TypedParameterValue a recordHHH-19340Gavin King
- Better leverage for-update-of to help minimize situations where follow-on is neededHHH-19339
- Improve performance of follow-on lockingHHH-19338
- Only perform follow-on locking when *explicitly* asked toHHH-19337
- Proper implementation for JPA extended locking scopeHHH-19336
- Redesign follow-on lockingHHH-19335
- CCE arising from tuple passed to HQL position() functionHHH-19334Gavin King
- Calling flush before query execution may cause PropertyValueException: Detached entity with generated idHHH-19333
- Figure out BulkManipulationTest issues with CockroachDBHHH-19332Karel Maesen
- query plan caching generates incorrect SQL, not taking parameters type into accountHHH-19331
- Error in lockstring generation in PostgreSQLHHH-19330Resolved issue: HHH-19330Jan Schatteman
- AssertionError visiting roots in query joinsHHH-19329
- @NaturalIdClassHHH-19328Gavin King
- overload SF.addNamedQuery() to take TypedQuery and return TypedQueryReferenceHHH-19327Resolved issue: HHH-19327Gavin King
- Jakarta Data CrudRepository is generated without Types in UpdateAll, InsertAll and SaveAll MethodsHHH-19326
- Upgrade to Jandex 3.3.0HHH-19325Resolved issue: HHH-19325Steve Ebersole
- Switch tests using hbm.xml to use mapping.xmlHHH-19324
- Add a CI job in the Hibernate ORM project for Hibernate ReactiveHHH-19323
- Batched unidirectional one-to-many update failingHHH-19322
- Improve inline documentation for @SuppressWarnings in registerStoredProcedureParameter, getResultList, and unwrap methodsHHH-19321Resolved issue: HHH-19321
- Assigned id value is not passed into BeforeExecutionGenerator#generate() method when allowAssignedIdentifiers() is true and id has been assignedHHH-19320Resolved issue: HHH-19320Marco Belladelli
- StatelessSession.findMultiple() accepting a LockModeHHH-19319Resolved issue: HHH-19319Gavin King
- follow-on locking and StatelessSessionHHH-19318Resolved issue: HHH-19318Gavin King
- Mark org.hibernate.boot.models as incubatingHHH-19317Steve Ebersole
- subselect fetching defined in maping.xml not honoredHHH-19316
- SINGLE_TABLE inheritance makes treat() pick wrong columns when multiple subclasses have a field with the same nameHHH-19315
- StackOverflowException when using onConflict with createCriteriaInsertValues and createCriteriaInsertSelectHHH-19314Andrea Boriero
- EntityGraph and OneToOne relationship is loading twice as many queriesHHH-19313
- BytecodeProviderImpl throwing java.lang.IndexOutOfBoundsExceptionHHH-19312
- NPE with Query Cache, Left Join Fetch, Inheritance on Both Sides, and No AssociationHHH-19311
- Simplified declaration of type for basic mappings in XMLHHH-19310
- Switch to Central Publishing Portal API for publishing to Maven CentralHHH-19309Marko Bekhta
- lock timeoutsHHH-19308
- NPE when entity class missing from persistence.xml is id of another entityHHH-19307Jan Schatteman
- Composite generator may not respect the event types of generators it consits ofHHH-19306Resolved issue: HHH-19306Marko Bekhta
- NPE in EntityEntryContext nonEnhancedEntityXref.get( entity )HHH-19305
- NPE in ResultSetMappingProcessor when using createNativeQuery with {x.*} notation and Entity with Embeddable that contains relational mappingsHHH-19304
- validate @Id fields against @IdClass in ProcessorHHH-19303Resolved issue: HHH-19303Gavin King
- composite ids with no id classHHH-19302
- Must import FQCN when generating metamodel class for inner Jakarta Data repository interfaceHHH-19301Resolved issue: HHH-19301Čedomir Igaly
- more ConstraintKindsHHH-19300Resolved issue: HHH-19300Gavin King
- <element-collection/> with LIST classification interpreted as BAGHHH-19299
- add convenience overloads of StatelessSession.get() which default GraphSemantic.LOADHHH-19298Resolved issue: HHH-19298Gavin King
- Register json functions in SingleStore community dialectHHH-19297Oleksandr Yeliseiev
- overload createSelectionQuery() to accept an EntityGraph instead of a result classHHH-19296Resolved issue: HHH-19296Gavin King
- Foreign keys are dropped when using schema = "public" after migrating to Spring Boot 3HHH-19295
- NodeBuilder collection*() doesn't work with enum collectionsHHH-19294
- Criteria isMember() doesn't work with collections mapped as arrayHHH-19293Resolved issue: HHH-19293
- Significant Memory Increase After Upgrading from Spring Boot 3.3.5 to 3.4.4HHH-19292
- Expressions.nullExpresion() in querydsl result in NPE in SqmExpressible with named parametersHHH-19291Resolved issue: HHH-19291Andrea Boriero
@SafeHtml(whitelistType = WhiteListType.NONE) allow <td>, <tr>
Description
Environment
Details
Assignee
UnassignedUnassignedReporter
ppBug Testcase Reminder (view)
Bug reports should generally be accompanied by a test case!
Bug Testcase Reminder (edit)
Bug reports should generally be accompanied by a test case!
Participants
Gunnar MorlingpRichard WalkerComponents
Fix versions
Affects versions
Priority
Minor
Details
Details
Assignee
Reporter
Bug Testcase Reminder (view)
Bug reports should generally be accompanied by a test case!
Bug Testcase Reminder (edit)
Bug reports should generally be accompanied by a test case!
Participants
Components
Fix versions
Affects versions
Priority
Activity
Gunnar MorlingApril 6, 2017 at 6:19 AM
Thanks for the investigation, @Richard Walker! As you say I'd prefer to leave things as they are then, so to not change semantics of the existing constraint.
Richard WalkerApril 6, 2017 at 12:41 AM
Yeah, not surprisingly it's more complicated than I had thought.
It was helpful for me to change the Validator code and run the test suite to see what happens.
(I'm currently working with 5.3.4.Final; it seems SafeHtmlValidator hasn't changed since this issue was resolved. I tried working with master branch, but a completely unrelated test currently fails, so I checked out 5.3.4.Final and did testing with that tag.)
Here's my modified/simplified SafeHtmlValidator:
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.internal.constraintvalidators.hv;
import java.util.Iterator;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.hibernate.validator.constraints.SafeHtml;
/**
* Validate that the string does not contain malicious code.
*
* It uses <a href="http://www.jsoup.org">JSoup</a> as the underlying parser/sanitizer library.
*
* @author George Gastaldi
* @author Hardy Ferentschik
*/
public class SafeHtmlValidator implements ConstraintValidator<SafeHtml, CharSequence> {
private Whitelist whitelist;
@Override
public void initialize(SafeHtml safeHtmlAnnotation) {
switch ( safeHtmlAnnotation.whitelistType() ) {
case BASIC:
whitelist = Whitelist.basic();
break;
case BASIC_WITH_IMAGES:
whitelist = Whitelist.basicWithImages();
break;
case NONE:
whitelist = Whitelist.none();
break;
case RELAXED:
whitelist = Whitelist.relaxed();
break;
case SIMPLE_TEXT:
whitelist = Whitelist.simpleText();
break;
}
whitelist.addTags( safeHtmlAnnotation.additionalTags() );
for ( SafeHtml.Tag tag : safeHtmlAnnotation.additionalTagsWithAttributes() ) {
whitelist.addAttributes( tag.name(), tag.attributes() );
}
}
@Override
public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
if ( value == null ) {
return true;
}
return Jsoup.isValid( value.toString(), whitelist );
}
}
The "trouble" with this change is that one of the test suite methods for this issue then fails: SafeHtmlValidatorTest#testValidationOfValidFragment()
:
@Test
@TestForIssue(jiraKey = "HV-873")
public void testValidationOfValidFragment() throws Exception {
descriptor.setValue( "whitelistType", WhiteListType.RELAXED );
assertTrue( getSafeHtmlValidator().isValid( "<td>1234qwer</td>", null ) );
}
It seems that "validity" now has a quite specific meaning for "body fragment": it means that the fragment must now also parse correctly if inserted directly inside a <body>
tag. So although <td>
is one of the permitted tags for "relaxed" mode, it has to be included inside <table><tr>...
.
So, to get the suite to pass, I had to replace the above test method with:
@Test
@TestForIssue(jiraKey = "HV-873")
public void testValidationOfInvalidFragment2() throws Exception {
descriptor.setValue( "whitelistType", WhiteListType.RELAXED );
assertFalse( getSafeHtmlValidator().isValid( "<td>1234qwer</td>", null ) );
}
@Test
@TestForIssue(jiraKey = "HV-873")
public void testValidationOfValidFragment() throws Exception {
descriptor.setValue( "whitelistType", WhiteListType.RELAXED );
assertTrue( getSafeHtmlValidator().isValid( "<table><tr><td>1234qwer</td></tr></table>", null ) );
}
So maybe this is not a desirable change to make, after all.
Gunnar MorlingApril 5, 2017 at 7:43 AM
@Richard Walker I'm not quite clear on the implications of the change you pointed to. Does it mean we wouldn't have to do that parsing-and-wrapping-in-a-document step anymore? If so, could you open a new issue, describing the suggested change for Hibernate Validator? Thanks!
Richard WalkerApril 5, 2017 at 6:46 AM
jsoup commit f44d6e64 of Thu Nov 24 14:36:13 2016 -0800 fixed the Jsoup#isValid()
method to require body content and to require that the content parse correctly (e.g., end tags match start tags). Should now be good to use as-is.
I use '@SafeHtml' on PsersonDto like this:
PersonDto.java
... @NotBlank @SafeHtml(whitelistType = WhiteListType.NONE) private String firstName; ...
And validate this on Spring Controller like this:
RegistrationController.java
... @RequestMapping(value = "/registrationUser", method = RequestMethod.POST) public String registrationUser(@Valid PersonDto personDto, BindingResult result) { logger.debug("registrationUser"); logger.debug("personDto: {}", personDto); if (result.hasErrors()) { for (ObjectError error : result.getAllErrors()) { logger.error("error: {}", error.getDefaultMessage()); } return formViewName; } else { personManager.registrationPerson(personDto); return completedViewName; } } ...
When I test, <script>, <b> tag is not allowed (result.hasErrors() is true), but <td>, <tr> is allowed. (result.hasErrors() is false)
When I use 'NONE' option, whitelist should allows onl text nodes. Is this hibernate validator's bug or Spring framework's bug?