next_token() ) { if ( '#tag' !== $tags->get_token_type() || $tags->is_tag_closer() ) { continue; } $tag = strtolower( (string) $tags->get_tag() ); $names = (array) $tags->get_attribute_names_with_prefix( '' ); if ( ! isset( $allowed[ $tag ] ) ) { $parts = array( $tags->get_modifiable_text() ); foreach ( $names as $name ) { $parts[] = array( $name, $tags->get_attribute( $name ) ); } $found[] = '<' . $tag . ">\0" . md5( (string) wp_json_encode( $parts ) ); continue; } foreach ( $names as $name ) { $value = $tags->get_attribute( $name ); $known = isset( $allowed[ $tag ][ $name ] ) || 0 === strpos( $name, 'data-' ) || 0 === strpos( $name, 'aria-' ) || ( 'img' === $tag && in_array( $name, self::IMAGE_ATTRIBUTES, true ) ); $bad = $known && is_string( $value ) && in_array( $name, $uri_attrs, true ) && trim( wp_kses_bad_protocol( $value, $protocols ) ) !== trim( $value ); if ( ! $known || $bad ) { $found[] = $name . ' on <' . $tag . ">\0" . md5( (string) wp_json_encode( $value ) ); } } } // A tag or a script left open swallows whatever the page prints after it. if ( $tags->paused_at_incomplete_token() ) { $found[] = __( 'an unfinished tag', 'agentimus' ) . "\0" . md5( substr( $html, -200 ) ); } return $found; } /** * @param array $block A parsed block. * @return string[] */ private static function scan_block_attributes( array $block ) { $found = array(); array_walk_recursive( $block['attrs'], static function ( $value ) use ( &$found ) { if ( is_string( $value ) && false !== strpos( $value, '<' ) ) { $found = array_merge( $found, self::scan( $value ) ); } } ); foreach ( $block['innerBlocks'] as $inner ) { $found = array_merge( $found, self::scan_block_attributes( $inner ) ); } return $found; } /** * @param string[] $added Labels of what the write would add. * @return \WP_Error */ private static function error( array $added ) { $message = __( 'Nothing was written: this would add markup that can run in a reader’s browser, or that this site only lets a person add. Agents may not store scripts, event handlers, javascript: links, iframes, styles or SVG, even under an administrator’s login, because a stored script runs with the owner’s session. To show a video or post, use its URL in an embed block. If the owner wants this exact markup, they can add it in the editor, and agent edits will then leave it in place. To show a literal “<”, write <.', 'agentimus' ); if ( $added ) { $message .= ' ' . sprintf( /* translators: %s: comma-separated markup that was refused, e.g. "