Skip to content
CAI
Software that uses CAICheck a score

rgrove/sanitize

65.3

Adequate · 6 November 2026

2k

lines of production code

Ruby

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

Behavioural changes

Migrate HTML parsing from Hpricot to Nokogiri

The library has switched its underlying HTML parser from Hpricot to Nokogiri (specifically using Nokogiri::HTML5). This change updates the core parsing logic in lib/sanitize.rb, replacing Hpricot-specific calls with Nokogiri equivalents for both document and fragment sanitization. The public API methods have been renamed for clarity (e.g., \clean\ is now \fragment\, \clean\_document\ is now \document\), with aliases provided for backward compatibility. This migration also introduces new transformer-based architecture for cleaning elements, comments, doctypes, and CDATA, and adds support for advanced CSS sanitization via the Crass library.

lib · high confidence

Refactored sanitization into modular transformers with enhanced security and configuration options

The sanitization engine has been restructured into a set of dedicated transformers (CleanCDATA, CleanComment, CleanCSS, CleanDoctype, CleanElement) to improve maintainability and performance. This change introduces stricter security measures, including a workaround for libxml2 code injection vulnerabilities in attributes like href and src, and the removal of potentially dangerous elements such as noscript and meta tags with non-UTF-8 charsets. Users gain new configuration capabilities, such as the :allow\doctype setting to control DOCTYPE handling, support for arbitrary HTML5 data-\ attributes, and the ability to specify :remove\_contents as an array of specific element symbols. Additionally, CSS sanitization is now handled by dedicated classes that enforce allowlists on both style attributes and style elements, with improved escaping to prevent premature closure of style tags.

lib/sanitize/transformers · high confidence

Sanitize 7.0.0: Deep config freezing and new CSS sanitization engine

This release introduces Sanitize 7.0.0, featuring a new \Sanitize::CSS\ class that leverages the Crass library to sanitize inline CSS properties and full stylesheets, including support for at-rules and protocol allowlisting. The configuration system has been hardened by deeply freezing built-in configs to prevent accidental or malicious alteration, and the \Config.merge\ method now safely handles deep merging while converting arrays to sets for better performance and syntax. Additionally, legacy output configuration options (\:output\ and \:output\_encoding\) have been removed.

lib/sanitize · high confidence

Sanitize 7.0.0: Drops support for older Ruby versions and updates tooling

This release increments the major version to 7.0.0 because support for end-of-life Ruby versions has been dropped; Ruby 3.1.0 is now the minimum supported version. The project has also modernized its development tooling by replacing the legacy Rakefile and RDoc-based documentation with Standard Ruby for code style, YARD for documentation generation, and Minitest for testing, while removing the Hpricot dependency in favor of Nokogiri.

(repo-wide) · high confidence

Sanitize configs are now frozen and use relative URL support

The built-in sanitization configurations (Basic, Relaxed, Restricted, and the new Default) are now deeply frozen to prevent accidental or malicious modification at runtime. Additionally, the Basic and Relaxed configs have been updated to allow relative URLs (via the :relative protocol specifier) in attributes like href, cite, and src, and the Relaxed config now includes a broader set of HTML5 elements, attributes, and CSS properties.

lib/sanitize/config · high confidence

Test coverage

Migrate test suite to Minitest

The test suite has been migrated from the Bacon testing framework to Minitest. This change replaces the legacy \test/spec\_sanitize.rb\ and \test/.bacon\ files with a comprehensive suite of new Minitest specs (e.g., \test/test\_clean\_comment.rb\, \test/test\_malicious\_html.rb\, \test/test\_transformers.rb\), ensuring that the library's sanitization logic, configuration handling, and transformer behaviors are verified using the modern Minitest runner.

test · high confidence

Dependencies

Sanitize gem requires Ruby 3.1+ and updates core dependencies

The Sanitize gem now requires Ruby 3.1.0 or later and enforces stricter dependency versions: Nokogiri must be at least version 1.16.8, and Crass is locked to the 1.0.2 series. Development tooling has been standardized with specific versions for Minitest (5.27.0), Rake (13.2.1), and Rubocop plugins, while the gemspec now explicitly requests Multi-Factor Authentication for publishing.

(dependencies) · high confidence

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 63 → 65 (+2.0)
  • Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.

Lenses

  • Code Health 69 → 69 (-0.0)
  • Architecture 80 → 82 (+1.8)
  • Maturity 54 → 58 (+4.0)
  • Readiness 65 → 65 (+0.0)
  • Security 100 → 100 (+0.0)

Resolved (3)

  • Inconsistent arity and configuration handling across entry points. Some methods accept an explicit config argument while their counterparts do not, despite the type having a Sanitize.config property and an initialize constructor. This forces users to guess whether to pass config or rely on a global/stateful default, and duplicates the logic for default config resolution.
  • Inconsistent constructor parameter types. CleanAttribute and CleanElement (under CSS) accept sanitizer_or_config, while the top-level CleanElement accepts only config. This creates ambiguity about whether a sanitizer instance or a raw config object is expected, and duplicates the transformer intent across namespaces without clear distinction.
  • Same inconsistency as above but within the CSS sub-namespace. Redundant overloads with and without config arguments create confusion about the source of truth for configuration.

New (2)

  • Hotspot: lib/sanitize/css.rb (lib/sanitize/css.rb)
  • Hotspot: lib/sanitize/transformers/clean_element.rb (lib/sanitize/transformers/clean_element.rb)

Changes since last survey

  • 17 commits — 16 feature/other, 1 fixes

By area

  • (root) — 14 commits
  • (repo) — 1 commit
  • lib/sanitize — 1 commit
  • test/test_clean_css.rb — 1 commit

Notable commits

  • fix: Fix namespace confusion when removing math and svg elements
  • change: Accept escaped < and > in serialized attribute values
  • change: Harden CSS sanitization against bad URL tokenizer differentials
  • change: Merge pull request #253 from flavorjones/card-918-html5-attr-escape-lt-gt
  • change: Reject CSS containing nodes beyond Crass's maximum nesting depth
  • change: Reject CSS properties that contain a {} block
  • change: Reject CSS style rules whose selectors contain a semicolon
  • change: Release 7.0.1
  • change: Release 7.0.2
  • change: Remove elements that legacy select parsing doesn't allow in select
  • change: Remove unused require "cgi"
  • change: Require Crass 1.0.8 or later
  • change: Require Nokogiri 1.19.7 and Ruby 3.2
  • change: Sanitize at-rules in any list of declarations as declarations
  • change: Sanitize at-rules nested in style rules as declarations
  • change: Simplify CSS property validation and parser options
  • change: Update changelog

Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

rgrove/sanitize was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 6 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit cb998dfea7192885c0e76b2127b9e6a680fabfb0 — the exact code this score is about.
  • Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
  • Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.2+preprod-5c4e66d9318b.