référence:
- Injection de modèle Spring Boot Thymeleaf pour le développement de la sécurité Java
- https://www.acunetix.com/blog/web-security-zone/exploiting-ssti-in-thymeleaf/
- https://github.com/veracode-research/spring-view-manipulation
La scène est lorsque le nom de la vue est contrôlable par l'utilisateur,
Le test réel a révélé qu'il était lié à la version de Spring Boot, qui est liée à la version par défaut de Thymeleaf.
botte à ressort: 1.5.1.RELEASE spring-boot-starter-thymeleaf: 2.1.5
spring boot: 2.0.0.RELEASE spring-boot-starter-thymeleaf: 3.0.9
spring boot: 2.2.0.RELEASE spring-boot- starter-thymeleaf: 3.0.11
La version 3.x de thymeleaf est uniquement affectée.
Le thymeleaf-spring5 de la version renderFragment 3.x est comme ceci:
if (!viewTemplateName.contains("::")) {
templateName = viewTemplateName;
markupSelectors = null;
} else {
IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
FragmentExpression fragmentExpression;
try {
fragmentExpression = (FragmentExpression)parser.parseExpression(context, "~{" + viewTemplateName + "}");
} catch (TemplateProcessingException var25) {
throw new IllegalArgumentException("Invalid template name specification: '" + viewTemplateName + "'");
}
Et 2.x thymeleaf-spring4 est comme ça
Configuration configuration = viewTemplateEngine.getConfiguration();
ProcessingContext processingContext = new ProcessingContext(context);
templateCharacterEncoding = getStandardDialectPrefix(configuration);
StandardFragment fragment = StandardFragmentProcessor.computeStandardFragmentSpec(configuration, processingContext, viewTemplateName, templateCharacterEncoding, "fragment");
if (fragment == null) {
throw new IllegalArgumentException("Invalid template name specification: '" + viewTemplateName + "'");
}