dschadow/JavaSecurity

GitHub: dschadow/JavaSecurity

这是一个Java安全演示仓库,包含多个展示Web安全防护和加密操作正确实现的示例应用程序。

Stars: 239 | Forks: 70

# Java 安全 本仓库包含多个涵盖不同安全主题的 Java Web 应用程序和命令行应用程序。请查看我的涵盖本仓库中大多数应用程序的[幻灯片](https://blog.dominikschadow.de/events)和[出版物](https://blog.dominikschadow.de/publications)。 # 环境要求 - [Java 25](https://dev.java) - [Maven 3](http://maven.apache.org) - [Mozilla Firefox](https://www.mozilla.org)(推荐,某些演示在其他浏览器中可能无法完全正常运行) - [Docker](https://www.docker.com)(将示例应用程序作为 Docker 容器运行所必需) # Web 应用程序详情 部分 Web 应用程序包含练习,部分仅用于检查和学习。每个 Web 应用程序的起始页上都提供了详细的说明。 部分 Web 应用程序基于 [Spring Boot](http://projects.spring.io/spring-boot),可以通过 **Application** 类中的 **main** 方法启动,或者在项目目录下通过 **mvn spring-boot:run** 启动。在使用 `mvn spring-boot:build-image` 创建镜像后,可以通过 `docker run -p 8080:8080 dschadow/[PROJECT]` 启动 Spring Boot 项目。其他 Web 应用程序要么包含可以通过 **mvn tomcat7:run-war** 启动的嵌入式 **Tomcat7 Maven plugin**,要么包含可以通过 **mvn jetty:run-war** 启动的嵌入式 **Jetty Maven plugin**。 ## access-control-spring-security 在 Spring Boot 应用程序中使用 [Spring Security](http://projects.spring.io/spring-security) 的访问控制演示项目。展示了如何安全地从数据库加载用户数据,而不使用可能被伪造的前端值。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## csp-spring-security 使用 Content Security Policy (CSP) 头的基于 Spring Boot 的 Web 应用程序。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## csrf-spring-security 基于 Spring Boot 的 Cross-Site Request Forgery (CSRF) 演示项目,通过使用 [Spring Security](http://projects.spring.io/spring-security) 在 Web 应用程序中防止 CSRF。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## csrf Cross-Site Request Forgery (CSRF) 演示项目,通过使用 [Enterprise Security API (ESAPI)](https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API) 在 JavaServer Pages (JSP) Web 应用程序中防止 CSRF。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080/csrf**。 ## direct-object-references 使用 Spring Boot 和 [Enterprise Security API (ESAPI)](https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API) 的直接对象引用(和间接对象引用)演示项目。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## intercept-me 基于 Spring Boot 的 Web 应用程序,用于试验作为拦截代理的 [OWASP ZAP](https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project)。目标是从后端接收 **SUCCESS**。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## security-header 安全响应头演示项目,将 **X-Content-Type-Options**、**Cache-Control**、**X-Frame-Options**、**HTTP Strict Transport Security (HSTS)**、**X-XSS-Protection** 和 **Content Security Policy (CSP)**(Level 1 和 2)头应用于 HTTP 响应。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080/security-header** 或 **https://localhost:8443/security-header**。 ## security-logging 利用 [OWASP Security Logging Project](https://www.owasp.org/index.php/OWASP_Security_Logging_Project) 的基于 Spring Boot 的 Web 应用程序。演示了如何在日志文件中记录安全相关的事件。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## session-handling-spring-security 基于 Spring Boot 的会话处理演示项目,利用 [Spring Security](http://projects.spring.io/spring-security) 和 [jasypt-spring-boot](https://github.com/ulisesbocchio/jasypt-spring-boot) 来保护 [Spring](http://spring.io) 配置(属性)文件。展示了如何限制对资源 (URL) 的访问,如何应用方法级安全性以及如何安全地存储和验证密码。使用 Spring Security 处理所有与安全相关的功能。启动时需要存在一个名为 **jasypt.encryptor.password** 的系统属性(或环境变量或命令行参数),其值为 **session-handling-spring-security**。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## session-handling 使用纯 Java 的会话处理演示项目。使用纯 Java 在登录后创建和更新 session id。需要支持 Servlet 3.1 的 Web 服务器。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080/session-handling**。 ## sql-injection 基于 Spring Boot 的 Web 应用程序,用于试验普通(易受攻击的)语句、带有转义输入的语句和预处理语句。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080**。 ## xss Cross-Site Scripting (XSS) 演示项目,通过使用输入验证、使用 [OWASP Java Encoder](https://www.owasp.org/index.php/OWASP_Java_Encoder_Project) 进行输出转义以及 Content Security Policy (CSP) 来防止 JavaServer Pages (JSP) Web 应用程序中的 XSS。启动后,在浏览器中打开 Web 应用程序:**http://localhost:8080/xss**。 # 命令行应用程序详情 以下项目演示了 Java 中不同库的加密用法。每个项目都包含一个或多个 JUnit **test** 类,用于测试演示项目的各种功能。 ## crypto-hash 使用 Java 通过不同哈希算法对密码进行哈希处理的加密演示。 ## crypto-java 使用纯 Java 通过非对称 (RSA) 和对称 (AES) 算法加密和解密数据,以及签名和验证数据 (DSA) 的加密演示。 ## crypto-shiro 使用 [Apache Shiro](http://shiro.apache.org) 通过对称 (AES) 算法加密和解密数据以及哈希数据(密码)的加密演示。 ## crypto-tink 使用 [Google Tink](https://github.com/google/tink) 通过非对称和混合加密、MAC 和数字签名加密和解密数据的加密演示。根据演示的不同,密钥要么是即时生成的,要么是从密钥集目录存储/加载的。**AWS KMS** 示例(名称中带有 AwsKms 的类)需要配置好的 AWS KMS 和已启用的主密钥。 # 元信息 ![Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/077f4bb8d1185428.svg) [![codecov](https://codecov.io/gh/dschadow/JavaSecurity/branch/main/graph/badge.svg?token=3raAUutQ8l)](https://codecov.io/gh/dschadow/JavaSecurity) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
标签:CISA项目, CSP, CSRF, Docker, GHAS, Java安全, JS文件枚举, Maven, Spring Boot, Spring Security, Streamlit, Web安全, XSS, 域名枚举, 安全标准, 安全示例, 安全编码, 安全防御评估, 漏洞情报, 漏洞演示, 漏洞验证, 网络安全, 蓝队分析, 访问控制, 请求拦截, 隐私保护