refactor: extract allowlist to lib/ with ALLOWLIST_FILE override#18
Merged
Conversation
SINENSIA
approved these changes
May 10, 2026
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
sanitize-htmlallowlist (tags, attributes, schemes, mode) fromserver.jsintolib/allowlist.js.ALLOWLIST_FILEenv var: when set, the JSON file at that path is loaded and used instead of the built-in allowlist.loadAllowlist) validates the file shape and fails fast at startup — malformed JSON, missing file, or non-arrayallowedTagsthrows before the server accepts requests, rather than silently falling back.Why
The original allowlist was inlined in the handler. With it lifted into its own module, different consumers can run the same image with different policies (a strict subset for UGC, a relaxed superset for trusted authoring tools) without forking the codebase or shipping their own build.
The "wholesale replace, no merge with defaults" choice is deliberate: merging surprises operators (you removed
iframefromallowedTagsbut inheritediframe's attributes from defaults). Forcing the override file to be self-contained makes the runtime allowlist trivially auditable.Test plan
npm test— 39/39 (7 new):loadAllowlistreturns the frozen default when unset.allowedTagstype, wrong top-level type.ALLOWLIST_FILEto a relaxed config and hits/validatewith<iframe>—safe: trueconfirms the override flows through tosanitize-html.Notes
DEFAULT_ALLOWLISTisObject.freezed so the module can't be mutated at runtime.chore: release 2.3.0PR will bump versions and consolidate the CHANGELOG entries.