Home > Database > Mysql Tutorial > Is `mysql_real_escape_string()` a Reliable Defense Against SQL Injection in All Character Encodings?

Is `mysql_real_escape_string()` a Reliable Defense Against SQL Injection in All Character Encodings?

Mary-Kate Olsen
Release: 2024-12-01 03:21:17
Original
160 people have browsed it

Is `mysql_real_escape_string()` a Reliable Defense Against SQL Injection in All Character Encodings?

Is mysql_real_escape_string() an Impregnable Shield Against SQL Injection?

A section on justinshattuck.com suggests that mysql_real_escape_string() is fallible against certain Asian character encodings. Specifically, it claims that the encoding bypasses mysql_real_escape_string() using BIG5 or GBK to smuggle dangerous characters into queries.

Is This Vulnerability Real?

According to Stefan Esser, the answer is a disconcerting yes. He claims that mysql_real_escape_string() falters when SET NAMES is employed. This method switches encoding to suit the application's needs without informing mysql_real_escape_string(). Consequently, if a multi-byte encoding allows backslash as the second, third, or fourth byte, trouble ensues. Mysql_real_escape_string() remains oblivious to this irregularity and fails to escape the characters correctly.

Protecting Your Website

Esser suggests that UTF-8 remains a safe encoding, but UTF-8 is not always an option. Unfortunately, mysql_set_charset, the safer alternative, is only available in recent PHP versions.

The above is the detailed content of Is `mysql_real_escape_string()` a Reliable Defense Against SQL Injection in All Character Encodings?. 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