当前位置: 首页 > news >正文

【038-安全开发篇】JavaEE应用SpringBoot框架MyBatis注入Thymeleaf模版注入

思维导图


知识点:

1、JavaEE-SpringBoot-WebAPP&路由
2、JavaEE-SpringBoot-Mybatis&注入
3、JavaEE-SpringBoot-Thymeleaf&SSTI

章节点

3、Java:
功能:数据库操作,文件操作,序列化数据,身份验证,框架开发,第三方库使用等.
框架库:MyBatis,SpringMVC,SpringBoot,Shiro,Log4j,FastJson等
技术:Servlet,Listen,Filter,Interceptor,JWT,AOP,反射机制待补充
安全:SQL注入,RCE执行,反序列化,脆弱验证,未授权访问,待补充
安全:原生开发安全,第三方框架安全,第三方库安全等,待补充

演示案例: SpringBoot-Web应用-路由响应 SpringBoot-数据库应用-Mybatis SpringBoot-模版引擎-Thymeleaf

Spring Boot是由Pivotal团队提供的一套开源框架,可以简化spring应用的创建及部署。它提供了丰富的Spring模块化支持,可以帮助开发者更轻松快捷地构建出企业级应用。Spring Boot通过自动配置功能,降低了复杂性,同时支持基于JVM的多种开源框架,可以缩短开发时间,使开发更加简单和高效。

SpringBoot-Web应用-路由响应

参考:https://springdoc.cn/spring-boot/
1、路由映射
@RequestMapping @GetMapping
2、参数传递
@RequestParam
3、数据响应
@RestController @Controller
@RestController注解相当于@ResponseBody+@Controller合在一起的作用。

@RestControllerpublicclassHelloController{//无参数访问响应@RequestMapping("/xiaodi")publicStringhello(){return"hello xiaodi";}//无参数指向GET方法访问响应@RequestMapping(value="/get",method=RequestMethod.GET)publicStringhelloGet(){return"hello get xiadi";}//有参数指向GET方法访问响应@RequestMapping(value="/getp",method=RequestMethod.GET)publicStringhellogetp(Stringname){return"hello get "+name;}//有参数指向POST方法访问响应@RequestMapping(value="/getpost",method=RequestMethod.POST)publicStringhelloGetParameters(Stringname){return"hello POST "+name;}}

SpringBoot-数据库应用-Mybatis

操作步骤:

0、数据库先创建需操作的数据

1、项目添加Mybatis&数据库驱动

-pom.xml

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency>

2、项目配置数据库连接信息
-application.yml

spring:datasource:url:jdbc:mysql://localhost:3306/demo01 username:root password:123456driver-class-name:com.mysql.cj.jdbc.Driver

3、创建User类用来操作数据库数据
-com.example.demo.entity.User

set get toString方法

4、创建Mapper动态接口代理类实现
-com.example.demo.mapper.UserMapper

@MapperpublicinterfaceUserMapper{@Select("select * from admin where id like '%${id}%'")//模糊查询,有安全危险publicList<User>findAll(Integerid);}

5、创建Controller实现Web访问调用
-com.example.demo.controller.UserController

@RestControllerpublicclassUserController{@AutowiredprivateUserMapperuserMapper;@RequestMapping(value="/getdata",method=RequestMethod.GET)//@ResponseBodypublicList<User>getdata(Integerid){List<User>all=userMapper.findAll(id);System.out.println(all);returnall;}}

可以在csdn搜索mybatis中SQL注入的文章,虽然有这种漏洞的可能性小,但是还是有可能

SpringBoot-模版引擎-Thymeleaf

  • 不安全的模版版本
    日常开发中:语言切换页面,主题更换等传参导致的SSTI注入安全问题(只有3.0.0到3.0.11版本有,后面就被修复了)
    漏洞参考:https://mp.weixin.qq.com/s/NueP4ohS2vSeRCdx4A7yOg

配置application.properties指向模版页面
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

@RequestMapping(value="/")publicStringindex(Modelmodel){model.addAttribute("data","hello xiaodi");return"index";}@GetMapping("/path")publicStringthymeleaf(Stringlang){returnlang;}<?xml version="1.0"encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>java-spring-thymeleaf</artifactId><version>1.0</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><!--latest--><version>2.2.0.RELEASE</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency></dependencies><properties><java.version>1.8</java.version></properties><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
http://www.gsyq.cn/news/109920.html

相关文章:

  • LobeChat能否部署在树莓派上?边缘设备运行可行性测试
  • 知乎开源Zhi-Create-Qwen3-32B:创意写作增强大模型
  • 【光子 AI】执行命令: marker_single 报错:IndexError: index is out of bounds for dimension with size 0 Recognizi
  • Qwen-Image-Edit-2509显存优化与推理加速实战
  • ssm基于微信小程序的汽车维修报销管理系统的设计与实现_k716u2bu
  • Qwen3-32B推理延迟优化:响应速度提升50%
  • 一键部署LobeChat:无需编码也能拥有现代化AI聊天界面
  • 2026年技术管理者面临双重挑战:83%企业遭遇技术与管理的双重困境,薪资涨幅高达60-90%!
  • 某物流企业AI战略落地全记录:AI应用架构师的8个关键动作
  • 达梦数据库实战指南:从环境搭建到核心操作
  • 基于YOLO-NAS深度学习模型的集装箱损伤检测自动化方案
  • LobeChat能否遗忘数据?符合GDPR右被遗忘权
  • 11.Java中的异常体系是怎样的
  • Kotaemon为何成为GitHub热门开源对话框架?
  • Unity MediaPipe插件实战指南:从零构建AI视觉应用
  • 卫星遥感数据核心参数解析:空间分辨率与时间分辨率
  • Kotaemon为何成为企业级AI对话框架新宠
  • LobeChat能否隔离数据?保障客户信息安全
  • 本地部署高颜值开源AI聊天应用LobeChat
  • vLLM在CUDA 12.1环境下的安装与配置
  • 防住了超卖,却输给了“少卖”?
  • 大专营销人跨领域突围难?基础薄弱也能啃下 AI 硬骨头!CAIE 认证成逆袭密码
  • FaceFusion:领先的人脸融合技术平台使用指南
  • Qwen-Image微调实战:让模型学会新车图生成
  • anything-llm Docker本地部署指南
  • 《60天AI学习计划启动 | Day 05: 项目实战 - 简单聊天机器人》
  • ACE-Step:开源高效音乐生成大模型解析
  • 16、Linux系统下外设使用指南
  • 2025-2026 北京靠谱工程律所指南:权威评测与核心解决方案对比 - 苏木2025
  • 2025年度北京五大靠谱大平层设计品牌企业推荐:资质齐全的大 - 工业品牌热点