Skip to content

Add IP-based access control to web server - #3

Merged
zas merged 2 commits into
mainfrom
feat/ip-access-control
Jul 10, 2026
Merged

zas merged 2 commits into
mainfrom
feat/ip-access-control

Conversation

@zas

@zas zas commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Add security features to the built-in web server: localhost-only by default and IP/CIDR-based access control.

Changes

Breaking change: the default bind address is now 127.0.0.1:8080 (was 0.0.0.0:8080). Users who expose the server on the network need to explicitly pass --bind 0.0.0.0:8080.

New flags:

Flag Env var Default Description
--bind DUPSONIC_BIND 127.0.0.1:8080 Address and port to listen on
--allow-ip DUPSONIC_ALLOW_IP (none — allow all) Comma-separated IPs or CIDR ranges to allow

Examples:

dupsonic serve                                          # localhost only
dupsonic serve --bind 0.0.0.0:8080                      # all interfaces, no filter
dupsonic serve --bind 0.0.0.0:8080 --allow-ip 192.168.1.0/24   # LAN only
DUPSONIC_BIND=0.0.0.0:8080 DUPSONIC_ALLOW_IP=10.0.0.0/8 dupsonic serve

Implementation:

  • axum middleware using ConnectInfo<SocketAddr> + ipnet crate for CIDR matching
  • Normalizes IPv4-mapped IPv6 addresses (::ffff:x.x.x.x → x.x.x.x)
  • Empty allow list = no filtering; non-empty = 403 for unmatched IPs
  • Startup prints the access policy for user confirmation

Testing

  • 10 new unit tests covering: empty list, allowed/denied IPv4, exact /32, IPv6, IPv4-mapped normalization, multiple ranges
  • All 63 tests pass (cargo test)
  • clippy clean

Docs

  • Updated README Web UI section
  • Updated ADVANCED.md with new "Access control" subsection

zas added 2 commits July 10, 2026 14:25
Link MusicBrainz Picard, Czkawka, dupeGuru, Duplicate Cleaner, and
MusicBrainz to their respective websites.
- Default bind to 127.0.0.1:8080 (localhost only) instead of 0.0.0.0
- Add --allow-ip flag (repeatable, CIDR notation) with DUPSONIC_ALLOW_IP env var
- Add --bind env var support via DUPSONIC_BIND
- Implement IP middleware: checks client IP against allow list, returns 403 for
  non-matching IPs. Handles IPv4-mapped IPv6 addresses.
- When --allow-ip is not set, all connections are permitted (no filtering)
- Add 10 unit tests for IP access control (IPv4, IPv6, CIDR, mapped addresses)
- Update README and ADVANCED.md with access control documentation
@zas
zas merged commit 6aa709c into main Jul 10, 2026
5 checks passed
@zas
zas deleted the feat/ip-access-control branch July 10, 2026 14:39
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