Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve validating sanitizer with context for why element/attribute is invalid #3780

Merged
merged 41 commits into from
Dec 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bf28199
Eliminate premature/redundant attribute checks from validate_attr_spe…
westonruter Oct 31, 2019
656ebb0
Remove redundant is_missing_mandatory_attribute check
westonruter Nov 16, 2019
a7f2750
Consolidate removal of elements without mandatory attributes
westonruter Nov 16, 2019
6475b70
Introduce illegal_cdata error code
westonruter Nov 16, 2019
ad440fa
Fix return value docs for validate_attr_spec_list_for_node
westonruter Nov 22, 2019
3f2f50e
Reuse check_attr_spec_rule_mandatory in is_missing_mandatory_attribute
westonruter Nov 23, 2019
3bb3d8e
Introduce specific error codes for attribute value violations
westonruter Nov 23, 2019
ad66b8f
Include list of missing mandatory attributes in validation error
westonruter Nov 23, 2019
35638c5
Extract AMP validator error codes and messages from spec
westonruter Nov 23, 2019
a2e20d6
Use constant in switch statement
westonruter Nov 23, 2019
ef80051
Fix removing emptyable-attributes and fix is_missing_mandatory_attribute
westonruter Nov 23, 2019
2d6ec3d
Add constants for error codes; improve CDATA error reporting
westonruter Nov 24, 2019
00eb55c
Add fine-grained error codes for CDATA
westonruter Nov 24, 2019
a6d0fc9
Revert "Extract AMP validator error codes and messages from spec"
westonruter Nov 24, 2019
15fb6dd
Fix validation of __amp_source_origin URL value
westonruter Nov 25, 2019
c55c58c
Eliminate duplicated testing; add code checking
westonruter Nov 25, 2019
7f4bf4e
Add DISALLOWED_DESCENDANT_TAG error code
westonruter Nov 25, 2019
df96667
Fix checking of empty URL before relative URL
westonruter Nov 25, 2019
7b32198
Add assertions for specific error codes
westonruter Nov 25, 2019
9808761
Move erroneous sanitiation inside of validate_tag_spec_for_node method
westonruter Nov 25, 2019
374e0d3
Add fine-grained error codes for elements that have bad ancestors or …
westonruter Nov 25, 2019
934bbd1
Add constants for normalized error codes used in style sanitizer
westonruter Nov 25, 2019
5da07dc
Ensure body present instead of raising error
westonruter Nov 25, 2019
b0dfd17
Improve error codes used in media converters; add error context data
westonruter Nov 25, 2019
2c42a07
Include spec_name in validation error
westonruter Nov 25, 2019
10b0c29
Include spec_name in validation errors raised by style sanitizer
westonruter Nov 25, 2019
6975bd0
Verify unique tag spec names when generating spec
westonruter Nov 26, 2019
e2db927
Remove redundant info from validation error now that spec_name provided
westonruter Nov 26, 2019
5e56cce
Fix up PHP comments
westonruter Nov 26, 2019
9067d6c
Remove obsolete DISALLOWED_DOMAIN checks
westonruter Nov 28, 2019
5d9c205
Add tests for INVALID_CDATA_CONTENTS and DISALLOWED_RELATIVE_URL
westonruter Nov 28, 2019
7470a24
Add test for MANDATORY_CDATA_MISSING_OR_INCORRECT
westonruter Nov 28, 2019
038caa7
Add tests for MANDATORY_TAG_ANCESTOR, DISALLOWED_TAG_ANCESTOR, and (n…
westonruter Nov 29, 2019
998c45c
Add test for INCORRECT_NUM_CHILD_TAGS
westonruter Nov 29, 2019
22b1869
Remove redundant validation error data; test for non-redundant data
westonruter Nov 29, 2019
8550fd7
Merge branch 'develop' of github.com:ampproject/amp-wp into add/inval…
westonruter Nov 30, 2019
322035b
Bring sanity to the code
schlessera Dec 3, 2019
dc76b9f
Merge branch 'develop' of github.com:ampproject/amp-wp into add/inval…
westonruter Dec 6, 2019
b96e4e7
Fix typos in comments and code style
westonruter Dec 6, 2019
827659a
Harmonize logic for getting stylesheet by URL
westonruter Dec 6, 2019
f7d00f9
Use SORT_REGULAR flag for array_unique() instead of serializing array…
westonruter Dec 6, 2019
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
6 changes: 3 additions & 3 deletions includes/sanitizers/class-amp-base-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract class AMP_Base_Sanitizer {
*
* @var array
*/
private $should_not_removed_nodes = [];
private $nodes_to_keep = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

😜

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, maybe I should mention I searched for usage first:

Image 2019-12-03 at 4 43 35 PM


/**
* AMP_Base_Sanitizer constructor.
Expand Down Expand Up @@ -439,15 +439,15 @@ public function remove_invalid_child( $node, $validation_error = [] ) {
}

// Prevent double-reporting nodes that are rejected for sanitization.
if ( isset( $this->should_not_removed_nodes[ $node->nodeName ] ) && in_array( $node, $this->should_not_removed_nodes[ $node->nodeName ], true ) ) {
if ( isset( $this->nodes_to_keep[ $node->nodeName ] ) && in_array( $node, $this->nodes_to_keep[ $node->nodeName ], true ) ) {
return false;
}

$should_remove = $this->should_sanitize_validation_error( $validation_error, compact( 'node' ) );
if ( $should_remove ) {
$node->parentNode->removeChild( $node );
} else {
$this->should_not_removed_nodes[ $node->nodeName ][] = $node;
$this->nodes_to_keep[ $node->nodeName ][] = $node;
}
return $should_remove;
}
Expand Down