Skip to content

Fix CWE-798/CWE-862/CWE-400 in PhotoAlbum-Java - #26

Merged
zhoufenqin (zhoufenqin) merged 2 commits into
mainfrom
fenzho/fix-cwe
Jul 28, 2026
Merged

zhoufenqin (zhoufenqin) merged 2 commits into
mainfrom
fenzho/fix-cwe

Conversation

@zhoufenqin

Copy link
Copy Markdown
Contributor

Fix CWE-798 / CWE-862 / CWE-400 in PhotoAlbum-Java

Addresses the findings (rule d626e486-27bc-48fc-8717-d8af875737de).

CWE-798 — Hard-coded credentials & DBA grant

  • oracle-init/01-create-user.sql: removed the hard-coded photoalbum/photoalbum and the GRANT DBA; the app user is created by the container from env vars with least-privilege grants only.
  • azure-setup.ps1: no longer hard-codes PostgreSQL passwords — reads from env or generates a strong random password per run, and stops printing the password to stdout.
  • Externalized all DB credentials to environment variables; added .env.example and git-ignored .env.

CWE-862 — Missing authorization on delete (DetailController.java)

  • Added Spring Security (SecurityConfig): POST /upload and POST /detail/*/delete now require authentication; the gallery stays public. Admin credentials come from APP_ADMIN_USERNAME/APP_ADMIN_PASSWORD env (fail-closed).

CWE-400 — Image decompression bomb (PhotoServiceImpl.java)

  • Read image dimensions from the header only (via ImageReader) with a max-pixel cap; removed the full ImageIO.read decode of attacker-controlled bytes.

Verification

mvn clean test (JDK 17) BUILD SUCCESS; Spring Security filter chain active.

Externalize Oracle/PostgreSQL credentials to environment variables (.env), drop the DBA grant and over-broad ANY privileges in favor of least-privilege grants, generate a strong random password in azure-setup.ps1 instead of hard-coding, stop printing the password to stdout, and update README to the env-based setup. Adds .env.example and git-ignores .env.
Require authentication for state-changing endpoints (/upload, /detail/*/delete) via Spring Security with env-based admin credentials; read image dimensions from header with a max-pixel cap to prevent decompression-bomb DoS.
@zhoufenqin
zhoufenqin (zhoufenqin) merged commit de25211 into main Jul 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants