Skip to content

Harden image and fix Snyk URL sanitization - #14

Merged
Luen merged 2 commits into
mainfrom
fix/snyk-security-hardening
Nov 2, 2026
Merged

Luen merged 2 commits into
mainfrom
fix/snyk-security-hardening

Conversation

@Luen

@Luen Luen commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Switch the digest image to a multi-stage python:3.12.16-alpine3.24 build that runs as a non-root user, clearing the Dockerfile Critical/High Snyk Container findings (rescanned image: no vulnerable paths).
  • Fix incomplete Google redirect URL sanitization (evilgoogle.com / httpevil:// lookalikes) that caused the medium Snyk Code finding; rescanned with 0 code issues.
  • Add .dockerignore and Dependabot Docker updates so base-image bumps stay automated.

Test plan

  • ruff check . --fix && ruff format .
  • pytest
  • docker compose build and docker compose run --rm digest python -m src --dry-run
  • Snyk Code scan: 0 issues
  • Snyk Container scan on media-alerts-digest:latest: no vulnerable paths
  • Confirm Snyk UI project counts drop after the PR is monitored/imported

Made with Cursor

…r URL unwrap.

Co-authored-by: Cursor <cursoragent@cursor.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Claude BugBot Analysis

Found 1 potential bug in this PR.

medium: 1

The URL-unwrap hardening in normalize.py is correct. The Alpine non-root Dockerfile creates a permissions regression with the existing ./data bind mount, which can break persistence of seen.json.

Comment thread Dockerfile
@@ -1,20 +1,35 @@
FROM python:3.12-slim
# syntax=docker/dockerfile:1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM: Non-root user (uid 1001) cannot write to the bind-mounted ./data directory

The image now runs as appuser (uid 1001) and only chowns /app/data inside the image. docker-compose.yml bind-mounts ./data:/app/data, and that mount hides the chowned directory. On a Linux host, ./data is owned by the host user (commonly uid 1000) or by root, so uid 1001 gets no write access. data/seen.json then can't be saved, so seen-URL state is lost or the run errors, and the digest re-emails the same items every day. Fix: make the container uid configurable and match the host, for example user: "${UID:-1000}:${GID:-1000}" in compose. Alternatively, document a required chown 1001:1001 data step, or use a named volume.

⚠️ Could not locate exact line in the diff. The bug is at Dockerfile:70.

Additional Locations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bb80a15. The image user is now uid/gid 1000, and compose runs as ${APP_UID:-1000}:${APP_GID:-1000} (documented in .env.example). The README has a one-time chown step for existing root-owned data/ directories left by the old root image. I checked locally that the container runs as 1000 and that save_seen/load_seen round-trip under /app/data.

@Luen Luen left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

src/normalize.py / tests: Looks good. _is_google_host correctly rejects evilgoogle.com, and the explicit http:///https:// prefix check closes the httpevil:// gap. Both cases have tests.

Dockerfile / compose (blocking): The BugBot finding is valid, and the real impact is a little worse than it says:

  • The image now runs as uid 1001, but docker-compose.yml bind-mounts ./data:/app/data, which hides the in-image chown. On a Linux host, uid 1001 usually can't write there.
  • The old image ran as root, so an existing production data/seen.json is root-owned. The first run after deploy would fail in save_seen() after send_digest(). The email goes out, the state isn't saved, and the same items get re-emailed every day. (run_schedule logs the exception and keeps looping, so this fails quietly.)

Nit: --mount=type=cache,target=/root/.cache/pip doesn't do anything while --no-cache-dir is set.

I'll push a fix: uid/gid 1000 in the image, a configurable user: in compose (APP_UID/APP_GID), a README migration note (chown the existing data/), and removal of the unused pip cache mount.

The bind mount hides the in-image chown, so uid 1001 couldn't write
seen.json on typical Linux hosts (and older root-owned data/ dirs), which
would re-email the same items after every run. Use uid/gid 1000, make the
compose user configurable via APP_UID/APP_GID, document the one-time chown
for existing data/, and drop the pip cache mount that --no-cache-dir made a
no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Claude BugBot Analysis

No new bugs found. The Docker, compose and normalize changes look correct. The earlier bind-mount permission issue is now handled by a configurable uid/gid.

No bugs were detected in this PR.

@Luen
Luen merged commit f935c06 into main Nov 2, 2026
11 checks passed
@Luen
Luen deleted the fix/snyk-security-hardening branch November 2, 2026 23:36
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.

1 participant