Hi dear WordPress Tooltips Plugin users, I hope this message brings a smile to your day and that you’re sharing lots of happy moments with those you hold dear. 🙂
We have released wordpress tooltips free 10.8.7 to fixed the issue “Stored Cross-Site Scripting” in 4 Hours – Securing Your WordPress Tooltips and Language Settings: Best Practices for File Uploads, Data Sanitization, and User Input Handling:
Key Changes Overview
1. Improvements to the Tooltip Import File
This file handles the import of tooltips from CSV files. The security issues addressed in this file include:
File Upload Validation: Ensuring only safe CSV files are uploaded.
SQL Injection Prevention: Using prepared SQL queries to prevent harmful database queries.
CSRF Protection: Implementing nonce validation to prevent unauthorized form submissions.
Sanitization & Escaping of User Inputs: Proper sanitization of user inputs to prevent malicious content.
Duplicate Check: Preventing the insertion of duplicate tooltips.
2. Enhancements to the Language Settings Panel
The language settings panel allows users to customize text for the tooltips. The security issues addressed in this file include:
Nonce Verification: Adding validation for nonces to prevent CSRF.
Escaping Outputs: Ensuring all output is escaped before being displayed to the user to prevent XSS vulnerabilities.
Sanitizing User Inputs: Ensuring all user inputs (like text fields) are sanitized properly.
Escaping URLs: Ensuring URLs are properly escaped to prevent malicious redirects.
Sanitizing Text and Content: Safely handling the content provided by users, especially when it includes HTML or user-generated content.
Changes to the Tooltip Import PHP File
1. File Upload Validation
One of the first steps in securing file uploads is validating the file type and ensuring the file is a legitimate CSV file.
Before: The code only checked the file extension.
After: We added an additional MIME type validation to ensure the uploaded file is a valid CSV.
2. Preventing SQL Injection
SQL Injection is one of the most common vulnerabilities. It occurs when a malicious user manipulates SQL queries to execute arbitrary SQL commands.
Before: Direct SQL queries were used with user input (e.g., tooltip titles) included in the query.
After: We implemented $wpdb->prepare() to safely prepare and escape SQL queries before executing them. This ensures user input is not directly inserted into SQL queries, preventing SQL injection attacks.
3. Preventing XSS (Cross-Site Scripting)
XSS attacks occur when an attacker injects malicious scripts into web pages viewed by other users. This is a serious issue when user-generated content is displayed.
Before: The tooltip content was inserted directly into posts without sufficient sanitization, potentially allowing malicious JavaScript.
After: We used wp_kses() to allow only safe HTML tags in the tooltip content. This ensures that dangerous HTML tags (like <script>) are stripped out, while allowing safe tags like <a>, <p>, and <i>.
4. CSRF (Cross-Site Request Forgery) Protection
CSRF allows an attacker to trick an authenticated user into submitting a form without their consent.
Before: Nonces were used in some parts of the form, but additional validation was not consistently implemented.
After: We added nonce validation at every critical action, such as file uploads and form submissions. This ensures that requests are legitimate and come from authorized users.
Changes to the Language Settings Panel PHP File
1. Nonce Verification
In the language settings panel, a form is used to accept user input for custom tooltip language. It’s important to ensure that the form submission is coming from a legitimate user and not a malicious actor.
Before: The code used check_admin_referer() in some places, but nonce verification wasn’t always consistently applied across all parts of the code.
After: We made sure that nonce verification is applied throughout the entire process where user input is submitted, ensuring that every action is protected from CSRF attacks.
2. Escaping Outputs
Any data that is output to the user from the database or user input needs to be escaped to prevent XSS attacks.
Before: The code displayed user input directly without escaping it, which could result in potential XSS vulnerabilities.
After: We used esc_html() and esc_url() to escape outputs before displaying them. This ensures that any HTML or URL included in the output is properly escaped, preventing malicious scripts from being executed.
3. Sanitizing User Inputs
User inputs, such as the language settings for tooltips, need to be sanitized before they are processed or displayed.
Before: User inputs were passed directly into the system without enough sanitization.
After: We added proper sanitization using WordPress functions like sanitize_text_field() and sanitize_textarea_field() to ensure user inputs are safe. For inputs that may contain HTML, we used wp_kses() to only allow a predefined set of safe HTML tags.
4. Escaping URLs
URLs provided by users (such as the link to the language selection page) should always be escaped using esc_url() to prevent malicious redirects.
Before: URLs were output directly without escaping, which could lead to unsafe redirects or link injections.
After: We used esc_url() to ensure that any URL is properly sanitized and escaped before being output to the browser.
5. Handling Content Properly
When handling content that may include HTML or special characters (e.g., the “Read More” text or glossary terms), we ensured it was safely handled.
Before: There was no clear sanitization of user-generated content that could contain potentially dangerous tags.
After: We ensured that all user-generated content is either sanitized or escaped, allowing only safe content to be stored and displayed.
Summary of Changes Made to Both Files
Here’s a summary of the improvements applied to both the Tooltip Import and Language Settings Panel PHP files:
File Upload Security (Tooltip Import)
File Type and MIME Type Validation: Ensuring only valid CSV files are uploaded by checking both the file extension and MIME type.
Sanitizing and Escaping Inputs: Using sanitize_text_field(), sanitize_textarea_field(), and wp_kses() to sanitize user inputs, ensuring that no malicious code is injected.
SQL Injection Prevention: Replacing raw SQL queries with $wpdb->prepare() to safely interact with the database and prevent SQL injection.
XSS Protection: Sanitizing content before displaying it, ensuring only safe HTML tags are allowed.
Language Settings Panel Security
Nonce Verification: Applying nonce validation consistently to prevent CSRF attacks.
Escaping Outputs: Using esc_html() for escaping text outputs and esc_url() for URLs to prevent XSS vulnerabilities.
Sanitizing User Inputs: Ensuring that all user input, including custom language settings, is sanitized using WordPress functions before being processed or displayed.
Escaping URLs: Ensuring that all URLs are properly escaped using esc_url() to avoid malicious redirects or link injections.
Conclusion
By implementing these changes, we’ve made the tooltip import system and language settings panel much more secure, following WordPress best practices. The primary focus was on preventing SQL injection, XSS vulnerabilities, and CSRF attacks while also ensuring that the user experience is smooth and that inputs and outputs are handled securely.






