Add opt-in Referer allowlist and rate limit to the sample server - #53
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Add opt-in Referer allowlist and rate limit to the sample server#53devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Related to #15 Co-Authored-By: Julian Perelli <jperelli@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Author
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
Related to #15 (and the demo overload from #7). The sample server only had the undocumented
HEADER_CHECKgate, which does nothing against<img src="https://server/?geojson=...">hotlinking. This adds two more opt-in env-var gates insrc/server.js, all off by default (no behaviour change unless set), and documents the three of them in a new README "Server configuration (access control)" table.ALLOWED_REFERERS— comma separatedRefererhostname allowlist (nginxvalid_referersflavour):example.comexact host;*.example.commatches the apex and subdomains; entries may be full URLs (only the hostname is kept); case-insensitivenoneallows requests with noReferer(curl / server-to-server). Without it, a missing or unparseableRefereris rejected403+ALLOWED_REFERERS_FAIL_MESSAGERATE_LIMIT_MAX/RATE_LIMIT_WINDOW(seconds, default60) — fixed-window in-memory counter per client IP (createRateLimiter), no new dependency. Fails with429+Retry-After+RATE_LIMIT_FAIL_MESSAGE. Client IP = firstX-Forwarded-Forentry, elseremoteAddress(same source the existing log line already used; README warns to only trust it behind a proxy).Middleware order:
HEADER_CHECK(unchanged, still applies to/health) →/healthshort-circuit → rate limit → referer check → existing log line./healthis exempt from the two new gates so DockerHEALTHCHECKkeeps working.To make this testable the express app construction moved into an exported
createApp(env = process.env); the default export is stillcreateServer(createApp()), soosmsm serve/import server from './server.js'are unaffected.Tests: new
test/server.test.js(21 cases) bootscreateApp(env)on an ephemeral port and hits/dynamic(template render, no browser) covering defaults,HEADER_CHECK, allALLOWED_REFERERSrules, and rate limiting incl. window reset with fake timers.npm testpasses (37 tests) on Node 22.12. Also smoke-testedosmsm servewithALLOWED_REFERERS=example.com:/health200, no-referer request 403, allowed referer renders a PNG.CHANGELOG has an
Unreleasedentry.Link to Devin session: https://app.devin.ai/sessions/358b3009bd1845f3ac40c3b8176e22b7
Open in Devin Desktop: https://app.devin.ai/desktop/session/358b3009bd1845f3ac40c3b8176e22b7?variant=devin
Requested by: @jperelli