From 97f275e5bde81da940d57a3805634a4ed3fd12ab Mon Sep 17 00:00:00 2001 From: bits-bytes-nn Date: Mon, 9 Nov 2026 07:54:04 +0900 Subject: [PATCH] feat(build): fail the build on post markup that runs code A post_convert hook parses each rendered post body with an HTML5 parser and rejects active elements, event handler and srcdoc/formaction attributes, and URL attributes with schemes posts do not use. Code blocks are text by then and pass. --- _plugins/safe_post_html.rb | 86 +++++++++++++++++++++++++++++++++++++ test/test_safe_post_html.rb | 56 ++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 _plugins/safe_post_html.rb create mode 100644 test/test_safe_post_html.rb diff --git a/_plugins/safe_post_html.rb b/_plugins/safe_post_html.rb new file mode 100644 index 0000000..6f1b598 --- /dev/null +++ b/_plugins/safe_post_html.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true +# +# Fails the build when a post's rendered body holds markup that would run code +# in a reader's browser or load another document in the site's origin: an +# active element (", + '', + "", + 'x', + 'x', + "x", + 'x', + '', + '', + "", + '
', + '', + '', + '', + "

p

" + ].freeze + + def test_each_way_markup_can_run_code_is_reported + ACTIVE.each do |html| + refute_empty SafePostHtml.violations("

x

#{html}"), html + end + end + + SAFE = [ + '그림', + '', + '점', + '안내', + '위로', + '글', + '메일', + '전화', + '', + '
<script>alert(1)</script> <img onerror=x>
', + 't' + ].freeze + + def test_what_posts_carry_is_not_reported + SAFE.each do |html| + assert_empty SafePostHtml.violations(html), html + end + end +end