Details
Also remove MEMCACHE_PORT=11211 from env.example since the port is no longer published.
The PHP application connects via the Docker internal hostname memcached:11211 (from session.save_path), which uses the app_net bridge network and does not require host-level port mapping.
Option 2: Bind memcached to localhost only (if host access is needed for debugging)
If host-level access to memcached is needed for debugging, bind only to the loopback interface:
ports:
- "127.0.0.1:${MEMCACHE_PORT:-11211}:11211"
This prevents remote access while allowing localhost:11211 connections from the Docker host.
Option 3: Enable SASL authentication (defense-in-depth)
Add SASL authentication to memcached as an additional layer:
command: >
memcached -m 512 -c 2048 -t ${NPROC:-4} -R 200 -S
environment:
MEMCACHED_USERNAME: "${MEMCACHED_USER:-avideo}"
MEMCACHED_PASSWORD: "${MEMCACHED_PASSWORD}"
Update the PHP session configuration accordingly:
session.save_path = "PERSISTENT=myapp avideo:${MEMCACHED_PASSWORD}@memcached:11211"
Note: Option 1 alone is sufficient and should be applied immediately. Options 2 and 3 provide defense-in-depth.
Credit
This vulnerability was discovered and reported by bugbunny.ai.