Feature/email disallow links - #756
Open
joeyamst wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens email content handling by preventing untrusted markdown (especially links) from being introduced into outbound emails, and by validating link schemes in backoffice-authored email bodies before they reach the mail preview/sending renderer.
Changes:
- Escapes reporter-provided text before inserting it into markdown email templates to prevent link/HTML injection in confirmation mails.
- Adds a markdown link-scheme validator and applies it to backoffice mail preview and “complete melding” inputs, allowlisting only
http,https,mailto, andtel. - Expands test coverage around escaping and scheme validation, plus adds an API test ensuring disallowed schemes are rejected with 422.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
meldingen/markdown.py |
Adds escaping for link/image/HTML-tag constructs and introduces a link-scheme validator over markdown tokens. |
meldingen/schemas/input.py |
Introduces allowlisted mail link schemes and validates mail body fields via AfterValidator. |
meldingen/mail.py |
Escapes reporter text before interpolating it into markdown mail templates. |
tests/test_markdown.py |
Adds tests for escaping behavior and link-scheme validation. |
tests/test_mail.py |
Adds a confirmation-mail regression test ensuring reporter text cannot create links. |
tests/test_input_schemas.py |
Adds schema-level validation tests for allowed vs disallowed link schemes in mail bodies. |
tests/api/v1/endpoints/test_mail.py |
Adds endpoint-level test asserting 422 on disallowed link schemes in preview mail body. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+41
to
+43
| def render_permissively(text: str) -> str: | ||
| html: str = PermissiveMarkdownIt("commonmark").render(text) | ||
| return html |
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.
Meldingen
Ticket: SIG-1234
Before opening a pull request, please ensure your branch is based on
mainand targetsmain.Check requirements when they are met (strikethrough when not applicable):
Be kind to code reviewers, please try to keep pull requests as small and focused as possible :)