Skip to content

Commit c1a57c3

Browse files
h4x3rotabclaude
andcommitted
Harden build reproducibility and input sanitization
Address PR review feedback: - Add TODO comments for image digest pinning in compose files - Use literal domains in multi-domain compose example (avoid env var injection) - Sanitize ROUTING_MAP domain/target values against haproxy config injection - Replace single-threaded http.server with ThreadingTCPServer for evidence serving Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5335ea2 commit c1a57c3

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

custom-domain/dstack-ingress/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ services:
112112
GATEWAY_DOMAIN: _.dstack-prod5.phala.network
113113
SET_CAA: true
114114
DOMAINS: |
115-
${APP_DOMAIN}
116-
${API_DOMAIN}
115+
app.example.com
116+
api.example.com
117117
ROUTING_MAP: |
118-
${APP_DOMAIN}=app-main:80
119-
${API_DOMAIN}=app-api:8080
118+
app.example.com=app-main:80
119+
api.example.com=app-api:8080
120120
volumes:
121121
- /var/run/tappd.sock:/var/run/tappd.sock
122122
- letsencrypt:/etc/letsencrypt

custom-domain/dstack-ingress/docker-compose.multi.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
services:
22
ingress:
3+
# TODO: pin by digest for production (dstacktee/dstack-ingress@sha256:...)
34
image: dstacktee/dstack-ingress:latest
45
ports:
56
- "443:443"
@@ -10,11 +11,11 @@ services:
1011
GATEWAY_DOMAIN: _.dstack-prod5.phala.network
1112
SET_CAA: true
1213
DOMAINS: |
13-
${APP_DOMAIN}
14-
${API_DOMAIN}
14+
app.example.com
15+
api.example.com
1516
ROUTING_MAP: |
16-
${APP_DOMAIN}=app-main:80
17-
${API_DOMAIN}=app-api:80
17+
app.example.com=app-main:80
18+
api.example.com=app-api:8080
1819
1920
volumes:
2021
- /var/run/tappd.sock:/var/run/tappd.sock

custom-domain/dstack-ingress/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
services:
22
dstack-ingress:
3+
# TODO: pin by digest for production (dstacktee/dstack-ingress@sha256:...)
34
image: dstacktee/dstack-ingress:latest
45
ports:
56
- "443:443"

custom-domain/dstack-ingress/scripts/entrypoint.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ setup_haproxy_cfg_multi() {
219219
target=$(echo "$target" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
220220
[[ -n "$domain" && -n "$target" ]] || continue
221221

222+
# Validate domain and target to prevent config injection
223+
if ! domain=$(sanitize_domain "$domain"); then
224+
echo "Error: Invalid domain in ROUTING_MAP: ${line}" >&2
225+
exit 1
226+
fi
227+
if ! target=$(sanitize_target_endpoint "$target"); then
228+
echo "Error: Invalid target in ROUTING_MAP: ${line}" >&2
229+
exit 1
230+
fi
231+
222232
# Strip protocol prefix from target if present
223233
target=$(parse_target_endpoint "$target")
224234

@@ -394,9 +404,15 @@ elif [ -n "$DOMAIN" ] && [ -n "$TARGET_ENDPOINT" ]; then
394404
setup_haproxy_cfg
395405
fi
396406

397-
# Start evidence HTTP server if enabled
407+
# Start evidence HTTP server if enabled (threaded to avoid blocking on slow clients)
398408
if [ "$EVIDENCE_SERVER" = "true" ]; then
399-
python3 -m http.server "$EVIDENCE_PORT" --directory /evidences &
409+
python3 -c "
410+
import http.server, socketserver, os
411+
os.chdir('/evidences')
412+
handler = http.server.SimpleHTTPRequestHandler
413+
with socketserver.ThreadingTCPServer(('', ${EVIDENCE_PORT}), handler) as s:
414+
s.serve_forever()
415+
" &
400416
echo "Evidence server started on port ${EVIDENCE_PORT}"
401417
fi
402418

0 commit comments

Comments
 (0)