2.3 KiB
2.3 KiB
XShop – Security
1. Principles
- Sanitize in, validate, escape out.
- Nonce + capability for every state-changing request.
- Use WP/WC APIs; no hand-rolled auth/crypto.
2. Input
sanitize_text_field,sanitize_textarea_field,sanitize_email,wc_clean,absint,esc_url_rawper type.- Validate: enums via allow-list, URLs via
wp_http_validate_urlwhere remote, dates viaDateTimeImmutable. - No
$_GET/$_POSTwithout sanitization. Noextract().
3. Output
esc_html,esc_attr,esc_url,esc_html__,wp_kses_post(only for intentionally HTML fields with allow-list),wp_ksesfor narrow HTML.- No
echo $raw.
4. CSRF
- Every POST/AJAX/REST mutation:
check_ajax_referer/wp_verify_nonce/X-WP-Nonceheader for REST. - REST:
permission_callbackchecks nonce and capability.
5. AuthZ
- Admin screens:
current_user_can('manage_options')ormanage_woocommercewhere appropriate (documented per screen). - Q&A:
edit_postsfor moderation; user can delete own question viadelete_postcap check. - Banners:
manage_options.
6. XSS
- No inline
onclickwith untrusted data. NoinnerHTMLwith unsanitized server data – DOM viatextContentor sanitized fragment. - Stored XSS: banner CTA/link, Q&A body – sanitized on save, escaped on render.
7. SQLi
- No raw SQL unless via
$wpdb->prepare. PreferWP_Query/WCCRUD. No string-concatenated queries.
8. Special Cases
- File uploads: use
wp_handle_upload+wp_check_filetype, no arbitrary file execution, no path traversal (sanitize_file_name,realpathcheck). - Redirects:
wp_safe_redirect+wp_validate_redirectallow-list. - Unserialize: never
unserializeuser data; use JSON. - Secrets: no inline secrets; no committed
.env. - Remote import: validate MIME, size cap, timeout, no SSRF (allow-list demo asset host if any).
9. Headers (theme-level)
- Theme does not override server headers; document recommended headers for host (CSP, etc.) in
docs/security.md.
10. Checklist per Feature
- Inputs sanitized + validated
- Nonce verified
- Capability checked
- Outputs escaped
- No raw SQL
- No unsafe redirect/unserialize/upload
11. Review Process
- PHPCS
WordPress.Security+ manual review before each release. - Security note in CHANGELOG.md.