Merged
Conversation
Address 5 critical findings from security audit: - C1: Sanitize custom embed HTML to prevent stored XSS (strip all non-iframe content) - C2: Escape URLs in format_body/1 to prevent reflected XSS via post messages - C3: Add authorization check to form export endpoint (IDOR fix) - C4: Replace String.to_atom/1 on user input with explicit whitelists (8 locations) - C6: Add IP-based rate limiting on authentication endpoints via Hammer Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Migrate to Hammer 7.0 API: define Claper.RateLimit module with use Hammer, add to supervision tree, and use hit/3 instead of check_rate/3. Remove old app-level config.
Move Claper.RateLimit above ClaperWeb.Endpoint so the ETS table is ready before any requests are accepted.
Merge the two separate case blocks into one to stay within Credo's complexity limit.
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
Addresses 5 critical findings from a comprehensive security audit of the codebase:
<iframe>tags with whitelisted attributes (src,width,height,frameborder,allow,allowfullscreen, etc.). Blocksjavascript:URIs insrc.Phoenix.HTML.html_escape/1before interpolating into<a>tags informat_body/1, preventing attribute injection via crafted URLs in post messages.authorize_event_access/2check toexport_form/2inStatController, matching the authorization pattern already used byexport_poll,export_quiz, andexport_all_messages.String.to_atom/1on user-controlled input with explicit whitelists orString.to_existing_atom/1across 6 files (converter, show, manage, dashboard, table actions, form component).hammerdependency with ETS backend and aRateLimitPlugthat enforces 10 requests/minute per IP on all authentication routes (login, registration, password reset, confirmation).C5 (unprotected file serving via
Plug.Static) is deferred for a separate PR.Test plan
mix test test/claper/embeds_test.exs— all 11 embed tests pass (including custom embed sanitization)mix format --check-formattedpasses<script>tag alongside iframe — verify only iframe is storedhttp://x.com" onclick="alert(1)"— verify"is escapedPOST /export/forms/:idas non-owner — verify 403