From d95445ea0456177e678fd5e193efada35602537b Mon Sep 17 00:00:00 2001 From: Rohit Vasudevamurthy Date: Tue, 26 Aug 2025 16:49:15 -0400 Subject: [PATCH 1/3] Add documentation for WordPress.Security.ValidatedSanitizedInput --- .../ValidatedSanitizedInputStandard.xml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml diff --git a/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml new file mode 100644 index 0000000000..15adcacfa7 --- /dev/null +++ b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml @@ -0,0 +1,64 @@ + + + + + + + + isset( $_POST['name'] ) ) { + $name = sanitize_text_field( + wp_unslash( $_POST['name'] ) + ); +} + ]]> + + + sanitize_text_field( + wp_unslash( $_POST['name'] ) +); + ]]> + + + + + (int) $_GET['id']; +} + ]]> + + + sanitize_text_field( $_POST['text'] ); +} + ]]> + + + + + array_map( + 'sanitize_text_field', + wp_unslash( $_GET['items'] ) +); + ]]> + + + wp_unslash( $_POST['data'] ); +} + ]]> + + + \ No newline at end of file From 0d6e34cff2fcd03799a5ece9e8423c7b2bbcc2de Mon Sep 17 00:00:00 2001 From: rooh-wp311 Date: Tue, 26 Aug 2025 18:34:01 -0400 Subject: [PATCH 2/3] Improve ValidatedSanitizedInput documentation based on reviewer feedback --- .../ValidatedSanitizedInputStandard.xml | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml index 15adcacfa7..6e9ebe635f 100644 --- a/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml +++ b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml @@ -7,56 +7,86 @@ - + isset( $_POST['name'] ) ) { - $name = sanitize_text_field( - wp_unslash( $_POST['name'] ) - ); + String interpolation with superglobals requires validation and sanitization. Using $_POST, $_GET, etc. directly in strings can lead to XSS attacks if the input contains malicious code. + ]]> + + + + + + + + + + + + + + sanitize_text_field( - wp_unslash( $_POST['name'] ) -); +$name = sanitize_text_field( wp_unslash( $_POST['name'] ) ); ]]> - + + + + (int) $_GET['id']; +if ( isset( $_POST['text'] ) ) { + $text = sanitize_text_field( wp_unslash( $_POST['text'] ) ); } ]]> - + sanitize_text_field( $_POST['text'] ); + $text = wp_unslash( $_POST['text'] ); } ]]> - + array_map( - 'sanitize_text_field', - wp_unslash( $_GET['items'] ) -); + WordPress automatically adds backslashes to certain superglobals. These must be removed using wp_unslash() or similar functions before sanitization to prevent double-escaping issues. + ]]> + + + - + wp_unslash( $_POST['data'] ); + $clean = sanitize_text_field( $_POST['data'] ); } ]]> From c5073df0b151bd229ed8891c95c1c44700721c0a Mon Sep 17 00:00:00 2001 From: rooh-wp311 Date: Tue, 26 Aug 2025 18:56:04 -0400 Subject: [PATCH 3/3] Fix XML structure: move standard blocks outside code_comparison sections --- .../ValidatedSanitizedInputStandard.xml | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml index 6e9ebe635f..6664121000 100644 --- a/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml +++ b/WordPress/Docs/Security/ValidatedSanitizedInputStandard.xml @@ -10,12 +10,12 @@ Validation ensures the input key exists (using isset(), empty(), array_key_exists(), or null coalescing operators). Unslashing removes WordPress's automatic backslashes using wp_unslash() or similar functions. Sanitization cleans the data using appropriate functions like sanitize_text_field(), absint(), etc. ]]> + + + - - - + + + - - - + + + - - - + + + - - -