Skip to content

Commit

Permalink
Temporarily suspend PHP Warnings on invalid tags
Browse files Browse the repository at this point in the history
Temporarily suspend PHP Warnings on invalid tags when processing Gist
HTML by setting the libxml_use_internal_errors() value to true.

The original value for libxml_use_internal_errors() is restored when the
processing is complete.

props @Dan0sz

See #80

Resolves #81
  • Loading branch information
salcode authored and bradyvercher committed Nov 24, 2024
1 parent d7ae673 commit abb722b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

* Temporarily suspend PHP Warnings on invalid tags when processing Gist HTML ([#81](https://github.com/bradyvercher/gistpress/issues/81))

## [v3.0.2] - 2020-01-16

* Sanitized the `id` attribute passed to the `[gist]` shortcode. This fixes an XSS vulnerability that could be exploited by untrusted contributors on multi-author sites. Thanks to [@cornerpirate](https://github.com/cornerpirate) for disclosing responsibly.
Expand Down
7 changes: 7 additions & 0 deletions includes/class-gistpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ public function process_gist_html( $html, array $args ) {
$html = '<?xml encoding="utf-8" ?>' . $html;

$dom = new DOMDocument();

// Temporarily suppress warnings for invalid tags.
$previous_libxml_use_internal_errors_value = libxml_use_internal_errors( true );

$dom->loadHTML( $html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED );

$lines = $dom->getElementsByTagName( 'tr' );
Expand Down Expand Up @@ -537,6 +541,9 @@ public function process_gist_html( $html, array $args ) {
$html = $this->process_gist_line_numbers( $html, $args['lines'], $args['lines_start'] );
}

// Reset to previous value.
libxml_use_internal_errors( $previous_libxml_use_internal_errors_value );

return $html;
}

Expand Down

0 comments on commit abb722b

Please sign in to comment.