Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@react.component
let make = (~comment: Actions.Fetch.t, ~cssTransitionGroupClassNames) => {
let rawMarkup = Marked.marked(comment.text, {gfm: true})
let innerHTML = {"__html": rawMarkup}
let sanitizedRawMarkup = SanitizeHtml.sanitize(rawMarkup)
let innerHTML = {"__html": sanitizedRawMarkup}
let nodeRef = React.useRef(Js.Nullable.null)

// The 500 must correspond to the 0.5s in:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@module("sanitize-html") external sanitize: string => string = "default"
16 changes: 16 additions & 0 deletions spec/rescript/rescript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
end
end

describe "comment markdown rendering" do
before do
Comment.create!(
author: "Author",
text: '**bold** <img src="missing.png" onerror="window.xssRan = true"><script>window.xssRan = true</script>'
)
visit "/rescript"
end

it "keeps markdown formatting and removes unsafe HTML" do
expect(page).to have_css(".js-comment-text strong", text: "bold")
expect(page).to have_no_css(".js-comment-text img", visible: :all)
expect(page).to have_no_css(".js-comment-text script", visible: :all)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code · Anthropic · claude-opus-5-5 · medium

Capybara skips hidden elements by default, and a script element is never visible, so these checks need visible: :all to be able to fail.

end
end

describe "form submission functions" do
let(:comment) { Comment.new(author: "Author", text: "This is a comment") }
let(:author_field) { "comment_author" }
Expand Down
Loading