Text: Markdown link/image resolver hook #59

Closed
opened 2026-12-04 16:21:16 +00:00 by faumaray · 1 comment
Owner

Context: Forge M12 renders wiki pages and release notes. Relative links and images must be rewritten to bounded server routes after rendering (path traversal and external image safety), but Void/Text/Markdown.hpp offers no resolver callback for link/image destinations (only the scheme allow-list).

Need (optional): a link/image resolver hook in the render options, e.g. std::function<std::string(std::string_view destination, bool image)>, applied after scheme validation and before HTML escaping/emitting.

Tests/gate: resolver receives each destination exactly once in document order, its output is escaped, a throwing/overlong resolver result is bounded, and javascript:/data: destinations are still dropped regardless of the hook. Forge post-processes the rendered HTML until this lands.

Context: Forge M12 renders wiki pages and release notes. Relative links and images must be rewritten to bounded server routes after rendering (path traversal and external image safety), but `Void/Text/Markdown.hpp` offers no resolver callback for link/image destinations (only the scheme allow-list). Need (optional): a link/image resolver hook in the render options, e.g. `std::function<std::string(std::string_view destination, bool image)>`, applied after scheme validation and before HTML escaping/emitting. Tests/gate: resolver receives each destination exactly once in document order, its output is escaped, a throwing/overlong resolver result is bounded, and javascript:/data: destinations are still dropped regardless of the hook. Forge post-processes the rendered HTML until this lands.
Author
Owner

Implemented in e6745ac on main.

  • MarkdownOptions::resolver (MarkdownResolver = std::function<std::string(std::string_view destination, bool image)>) is applied after the scheme allow-list check and before HTML escaping, once per emitted link/image destination in document order.
  • Its output is escaped like any other destination.
  • javascript:/data:/vbscript: destinations are still dropped and never reach the resolver (entity-smuggled variants included).
  • A throwing resolver falls back to the original validated destination; an overlong result is reported as MarkdownError::Code::output_limit via MarkdownLimits::max_output.
  • Resolver is not called for images when allow_images == false (nothing is emitted).
  • Tests in tests/standalone/Text/Markdown.cpp: ordering/exactly-once, escaping, throw fallback, overlong bound, unsafe-destination bypass, disallowed images. Text+Testing suite: 627 tests, 624 passed, 3 skipped, 0 failed.
Implemented in e6745ac on `main`. - `MarkdownOptions::resolver` (`MarkdownResolver = std::function<std::string(std::string_view destination, bool image)>`) is applied after the scheme allow-list check and before HTML escaping, once per emitted link/image destination in document order. - Its output is escaped like any other destination. - `javascript:`/`data:`/`vbscript:` destinations are still dropped and never reach the resolver (entity-smuggled variants included). - A throwing resolver falls back to the original validated destination; an overlong result is reported as `MarkdownError::Code::output_limit` via `MarkdownLimits::max_output`. - Resolver is not called for images when `allow_images == false` (nothing is emitted). - Tests in `tests/standalone/Text/Markdown.cpp`: ordering/exactly-once, escaping, throw fallback, overlong bound, unsafe-destination bypass, disallowed images. Text+Testing suite: 627 tests, 624 passed, 3 skipped, 0 failed.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Void/Library#59