Is `mysql_real_escape_string()` Truly Safe: Can Asian Character Encodings Bypass its Protection?

Susan Sarandon
Release: 2024-10-26 18:17:02
Original
828 people have browsed it

Is `mysql_real_escape_string()` Truly Safe: Can Asian Character Encodings Bypass its Protection?

Does mysql_real_escape_string() Fully Safeguard Against SQL Injection?

A recent claim circulated that mysql_real_escape_string() can be bypassed with certain Asian character encodings, specifically Big5 and GBK. Is this assertion valid, and if it is, how can you protect your website without resorting to prepared statements?

The Vulnerablity

According to Stefan Esser, mysql_real_escape_string() does present a vulnerability when the SET NAMES command is used. This command alters the character encoding, rendering mysql_real_escape_string() oblivious to certain multi-byte encodings that employ backslashes as additional bytes. This incorrect escaping can compromise your website's security.

Safeguards

While UTF-8 encoding is not susceptible to this exploit, it is essential to use mysql_set_charset to safely alter encodings. This function, however, is only available in newer PHP versions. If you cannot employ prepared statements or mysql_set_charset, you may need to explore alternative methods to protect your website from SQL injection attacks.

The above is the detailed content of Is `mysql_real_escape_string()` Truly Safe: Can Asian Character Encodings Bypass its Protection?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!