Security hardening: docs CSP, X-Request-ID validation, log redaction, webhook SSRF guard - #179
Open
Junman140 wants to merge 1 commit into
Open
Conversation
…ion, webhook SSRF guard - SmartDropLabs#129: relax helmet's default CSP for the /api-docs Swagger UI route only - SmartDropLabs#133: validate client X-Request-ID (max 128 chars, [A-Za-z0-9_-]); fall back to a server-generated ID otherwise; document trust boundary - SmartDropLabs#94: extend log redaction to arrays, string-embedded secret query params, and Authorization keys; preserve whsec_**** partial reveal; cover non-sensitive fields - SmartDropLabs#96: add delivery-time SSRF guard (DNS resolve + IP pinning, no redirects) blocking private/internal targets; reduce test-endpoint error detail to a generic category with raw detail kept server-side; add per-IP rate-limit aggregation test
|
@Junman140 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security hardening addressing issues #129, #133, #94, and #96.
#129 — helmet() CSP breaks Swagger UI at
/api-docssrc/middleware/csp.jsexportingdocsCspMiddleware, which relaxes the Content-Security-Policy only for the/api-docsroute (allows inline scripts/styles that swagger-ui-express injects). The strict default CSP still protects the real API surface.#133 — X-Request-ID trusted from client with no validation
src/middleware/requestId.jsnow validates any client-suppliedX-Request-ID(max 128 chars, charset[A-Za-z0-9_-]). Invalid/oversized values are discarded and a fresh server-generated ID is used instead. Documented in code comments and the README as an optional, non-authoritative correlation hint.#94 — Log redaction only matched top-level-ish substring keys
src/services/logRedaction.js: redacts arrays as first-class nodes (plain arrays of secret-shaped strings), scans every string value forwhsec_secrets andtoken=/secret=/key=query params embedded in URLs, and treatsapi_key/ApiKeyetc. as sensitive keys. Preserves thewhsec_****partial reveal and keeps non-sensitive fields (asset_code, price_usd, delivery_id) intact. Newtest/logger.test.js.#96 — Webhook test endpoint as SSRF oracle
src/services/ssrfGuard.js: validates targets against private/internal ranges (RFC-1918, loopback, link-local, CGNAT, IPv6 ULA/link-local, IPv4-mapped) at delivery time, re-resolves DNS per request, and pins the connection to the validated public IP (Host header preserved, redirects disabled) to close DNS-rebinding. The/webhooks/:id/testendpoint refuses blocked targets with422 WEBHOOK_TARGET_BLOCKED(never attempted), and itslast_erroris now a generic category (unreachable/error_response/delivery_failed) with raw detail kept only in server logs. Per-IP rate-limit aggregation verified by a new test.Test plan
npm test). New coverage:test/logger.test.js,test/webhooks.ssrf.test.js, extendedtest/requestId.test.jsandtest/api-docs.test.js.test/webhooks.routes.test.jsandtest/webhookDispatcher.test.jsto mock the SSRF guard so unit tests stay offline.Closes #129
Closes #133
Closes #94
Closes #96