ka215/wp-ignitor

Data Must be Sanitized, Escaped, and Validated

Closed this issue · 1 comments

ka215 commented

When you include POST/GET/REQUEST/FILE calls in your plugin, it's important to sanitize, validate, and escape them. The goal here is to prevent a user from accidentally sending trash data through the system, as well as protecting them from potential security issues.

SANITIZE: Data that is input (either by a user or automatically) must be sanitized as soon as possible. This lessens the possibility of XSS vulnerabilities and MITM attacks where posted data is subverted.

VALIDATE: All data should be validated, no matter what. Even when you sanitize, remember that you don’t want someone putting in ‘dog’ when the only valid values are numbers.

ESCAPE: Data that is output must be escaped properly when it is echo'd, so it can't hijack admin screens. There are many esc_*() functions you can use to make sure you don't show people the wrong data.

To help you with this, WordPress comes with a number of sanitization and escaping functions. You can read about those here:

https://developer.wordpress.org/plugins/security/securing-input/
https://developer.wordpress.org/plugins/security/securing-output/

Remember: You must use the most appropriate functions for the context. If you’re sanitizing email, use sanitize_email(), if you’re outputting HTML, use esc_html(), and so on.

An easy mantra here is this:

Sanitize early
Escape Late
Always Validate

Clean everything, check everything, escape everything, and never trust the users to always have input sane data. After all, users come from all walks of life.

Example(s) from your plugin:

wp-ignitor-1.0.0-beta.2/src/admin.php:98: $_page = (string)filter_var( $_REQUEST['page'] ?? '', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_BACKTICK | FILTER_FLAG_STRIP_HIGH );
wp-ignitor-1.0.0-beta.2/src/admin.php:488: 'current_tab' => (string)filter_var( $_REQUEST['tab'] ?? 'globals', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_BACKTICK | FILTER_FLAG_STRIP_HIGH ),

We ask you use the sanitize functions from WordPress rather than filter_var, as the former is built for use with WordPress specifically and can account for it's usecases.

ka215 commented

Improved the sanitization process of request values reference by super global variable.

wp-ignitor-1.0.0-beta.2/src/admin.php:98:

$_page = sanitize_text_field( $_REQUEST['page'] ?? '' );

wp-ignitor-1.0.0-beta.2/src/admin.php:488:

'current_tab' => sanitize_key( $_REQUEST['tab'] ?? 'globals' ),

also,

$params[$_k] = filter_input( INPUT_POST, $_k, FILTER_DEFAULT );
if ( strpos( $params[$_k], PHP_EOL ) !== false ) {
    $params[$_k] = sanitize_textarea_field( $params[$_k] );
} else {
    $params[$_k] = sanitize_text_field( $params[$_k] );
}