Skip to content

Conversation

@dereuromark
Copy link
Contributor

Summary

  • Adds SafeMode configuration class for XSS protection
  • Blocks dangerous URL schemes (javascript:, vbscript:, data:, file:)
  • Filters event handler attributes (onclick, onload, onerror, etc.)
  • Handles raw HTML with three modes: escape (default), strip, or allow
  • Adds safeMode option to DjotConverter constructor

Usage

// Enable with defaults
$converter = new DjotConverter(safeMode: true);

// Enable strict mode (strips raw HTML completely)
$converter = new DjotConverter(safeMode: SafeMode::strict());

// Custom configuration
$safeMode = SafeMode::defaults()
    ->addDangerousScheme('mailto')
    ->setAllowedSchemes(['https'])
    ->setRawHtmlMode(SafeMode::RAW_HTML_STRIP);
$converter = new DjotConverter(safeMode: $safeMode);

Test plan

  • 27 new tests covering all safe mode functionality
  • All existing tests pass (689 tests, 2130 assertions)
  • phpcs and phpstan pass

Closes #2

🤖 Generated with Claude Code

- Add SafeMode configuration class with URL sanitization,
  attribute filtering, and raw HTML handling modes
- Block dangerous URL schemes (javascript:, vbscript:, data:, file:)
- Filter event handler attributes (onclick, onload, etc.)
- Support for escaping, stripping, or allowing raw HTML
- Add safeMode option to DjotConverter constructor
- Add 27 tests covering all safe mode functionality

Closes #2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 75.92593% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.39%. Comparing base (2e58bc3) to head (7a7a2c4).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/SafeMode.php 67.79% 19 Missing ⚠️
src/Renderer/HtmlRenderer.php 83.78% 6 Missing ⚠️
src/DjotConverter.php 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master       #3      +/-   ##
============================================
- Coverage     93.01%   92.39%   -0.63%     
- Complexity     1202     1246      +44     
============================================
  Files            49       50       +1     
  Lines          2977     3076      +99     
============================================
+ Hits           2769     2842      +73     
- Misses          208      234      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark dereuromark marked this pull request as ready for review November 28, 2025 09:24
@dereuromark dereuromark merged commit 8774dca into master Nov 28, 2025
4 of 6 checks passed
@dereuromark dereuromark deleted the feature/safe-mode branch November 28, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security Hardening Plan

2 participants