How sonarsource-demos/demo-java-security works
1. This repo is a single Maven-based Java web module, not a multi-service system. The runtime boundary is a servlet container serving JSPs from src/main/webapp, with Java classes under src/main/java/demo/security.
2. The application layer is split into servlet entry points: HomeServlet, UserServlet, FileServlet, ScriptServlet, and Insecure. These are the main request-handling units that receive HTTP traffic, interpret parameters, and route work to helpers or views.
3. web.xml is the deployment boundary that defines how the web app is wired in the container. It is the place where servlet mappings, startup behavior, and web-facing configuration would be applied.
4. The view layer is minimal and JSP-based: index.jsp and user.jsp. These pages are the UI/rendering endpoints, likely populated by servlet-provided request attributes rather than a separate frontend framework.
5. Insecure.java is the core demo artifact. The README says it intentionally contains vulnerabilities and security hotspots, and the project is designed to exercise SonarQube security rules, including custom source/sink/sanitizer definitions.
6. Security-related helper code is concentrated in demo.security.util. DBUtils, WebUtils, Utils, SessionHeader, BrowserSearchUtility, RSAKeyGeneratorUtil, and AsymmetricEncryptionUtil form the shared utility boundary used by the servlets and the security demo code.
7. The data flow is typical servlet-to-helper-to-view: request parameters enter a servlet, are passed through utility methods, and then either touch external systems such as the database or are rendered back into JSPs. The intentionally insecure flows in Insecure are there to demonstrate unsafe parameter propagation and sanitization gaps.
8. The repository includes explicit cryptography utilities, suggesting part of the demo covers key generation and asymmetric encryption behavior. RSAKeyGeneratorUtil and AsymmetricEncryptionUtil are separate from the web tier and can be tested independently.
9. There is a likely persistence boundary, but no dedicated DAO/module split. DBUtils and credentials.properties imply direct database access from the web/utility layer rather than a layered ORM architecture.
10. Testing focuses on utility behavior rather than end-to-end web flows. The test set includes AsymmetricEncryptionUtilTest, RSAKeyGeneratorUtilTest, WebUtilsTest, and a basic AppTest, which indicates the most important verification points are helper logic and security-related transformations.
11. Build and analysis tooling are part of the architecture because they drive the repo’s purpose. pom.xml defines the Maven build, .github/workflows/maven.yml and buildspec.yml provide CI integration, and run.sh re-runs the project through SonarQube with the custom security config s3649JavaSqlInjectionConfig.json.
12. Overall, the system boundary is a demo web app whose primary concern is security analysis rather than business functionality. The key architecture is: HTTP request -> servlet -> utility/DB/crypto helpers -> JSP response, with Insecure.java serving as the intentionally flawed code path for static-analysis training.
Main entry points: web.xml web.xml · Insecure.java Insecure · UserServlet.java UserServlet · WebUtils.java WebUtils
Components 24
Web tier
Servlet entry points, JSP views, and deployment wiring.
- HomeServlet · Home request handler and route entry point.
src/main/java/demo/security/servlet/HomeServlet.java - UserServlet · User-facing request handler for profile or form flows.
src/main/java/demo/security/servlet/UserServlet.java - FileServlet · Request handler for file-oriented operations.
src/main/java/demo/security/servlet/FileServlet.java - ScriptServlet · Request handler for script-driven or demo flows.
src/main/java/demo/security/servlet/ScriptServlet.java - Insecure · Intentionally flawed security-demo code path.
src/main/java/demo/security/servlet/Insecure.java - web.xml · Container wiring, servlet mappings, and web deployment setup.
src/main/webapp/WEB-INF/web.xml - index.jsp · Primary landing page rendered by the web tier.
src/main/webapp/index.jsp - user.jsp · User-facing JSP rendered from servlet data.
src/main/webapp/user.jsp
Security utilities
Shared helpers for validation, storage, session handling, and crypto.
- DBUtils · Direct database access and persistence helper.
src/main/java/demo/security/util/DBUtils.java - WebUtils · Common web/parameter processing helper.
src/main/java/demo/security/util/WebUtils.java - Utils · General-purpose utility methods used across the app.
src/main/java/demo/security/util/Utils.java - SessionHeader · Session and header handling helper.
src/main/java/demo/security/util/SessionHeader.java - BrowserSearchUtility · Browser or search-related helper logic.
src/main/java/demo/security/util/BrowserSearchUtility.java - RSAKeyGeneratorUtil · RSA key generation utility.
src/main/java/demo/security/util/RSAKeyGeneratorUtil.java - AsymmetricEncryptionUtil · Asymmetric encryption and decryption utility.
src/main/java/demo/security/util/AsymmetricEncryptionUtil.java
Tests
Focused unit tests for utility and crypto behavior.
- WebUtilsTest · Tests web utility behavior.
src/test/java/WebUtilsTest.java - RSAKeyGeneratorUtilTest · Tests RSA key generation behavior.
src/test/java/RSAKeyGeneratorUtilTest.java - AsymmetricEncryptionUtilTest · Tests asymmetric crypto behavior.
src/test/java/AsymmetricEncryptionUtilTest.java - AppTest · Basic repository smoke test.
src/test/java/AppTest.java
Build and analysis
Maven build, CI, and security-analysis configuration.
- pom.xml · Maven project definition and dependency/build setup.
pom.xml - CI workflows · GitHub Actions and buildspec automation for build and analysis.
.github/workflows/maven.yml - buildspec.yml · Build pipeline definition for hosted CI.
buildspec.yml - run.sh · Script to run the project through SonarQube analysis.
run.sh - s3649 config · Custom security-source/sink configuration for analysis.
s3649JavaSqlInjectionConfig.json
Connections 26
- web.xml → HomeServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → UserServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → FileServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → ScriptServlet: maps · Deployment descriptor wires servlet entry points.
- web.xml → Insecure: maps · Deployment descriptor wires servlet entry points.
- HomeServlet → WebUtils: uses · Servlet delegates request handling to web helpers.
- HomeServlet → index.jsp: renders · Servlet forwards to JSP view.
- UserServlet → WebUtils: uses · Servlet delegates request handling to web helpers.
- UserServlet → DBUtils: uses · User flow reaches persistence helper.
- UserServlet → user.jsp: renders · Servlet forwards to JSP view.
- FileServlet → Utils: uses · File flow relies on shared helpers.
- ScriptServlet → BrowserSearchUtility: uses · Script flow uses browser/search helper logic.
- ScriptServlet → SessionHeader: uses · Script flow touches session/header helper logic.
- Insecure → DBUtils: uses · Intentionally unsafe flow can reach persistence boundary.
- Insecure → WebUtils: uses · Intentionally unsafe parameter flow through web helpers.
- Insecure → Utils: uses · Demo vulnerability path exercises shared utilities.
- Insecure → AsymmetricEncryptionUtil: uses · Security demo may route into crypto helpers.
- RSAKeyGeneratorUtil → AsymmetricEncryptionUtil: supports · Key generation underpins asymmetric encryption workflows.
- WebUtilsTest → WebUtils: tests · Unit coverage for web utility behavior.
- RSAKeyGeneratorUtilTest → RSAKeyGeneratorUtil: tests · Unit coverage for key generation behavior.
- AsymmetricEncryptionUtilTest → AsymmetricEncryptionUtil: tests · Unit coverage for asymmetric encryption behavior.
- AppTest → pom.xml: runs under · Smoke test is part of the Maven project.
- CI workflows → pom.xml: builds · CI uses the Maven project definition.
- buildspec.yml → pom.xml: builds · Hosted CI uses the Maven project definition.
- run.sh → s3649 config: loads · Analysis script invokes custom security configuration.
- run.sh → pom.xml: runs · Script executes the Maven-based project analysis.