Em đang làm một cái form đăng nhập bằng Spring. Hôm nọ thầy bảo là phải xử lý cái vụ SQL Injection bằng param hay set param gì đó em không nghe được. Không biết anh có liên tưởng đến khái niệm nào có thể trả lời giúp em được không ạ
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Cái mà thầy em nói đó chính là PreparedStatement interface. Khi các tham số đi qua interface này sẽ được các thư viện cài đặt (ví dụ hibernate). Họ sẽ xử lý các tham số giúp em để loại bỏ hoặc thay thế các ký tự đặc biệt để giảm thiểu rủi ro với dữ liệu đầu vào.
Tuy nhiên không có gì là an toàn tuyệt đối cả, tốt hơn hết là khi dữ liệu được gửi lên server thì em hãy validate trước cho thật cẩn thận trước khi đưa vào query nhé.
a ơi trước khi gửi lên server, mình validate kiểu như nào vậy ạ. có phải là chuỗi đấy chỉ là chuỗi String k chứa các ký tự đặ biệt hay sao ạ
Nó sẽ tuỳ vào nghiệp vụ em ạ, ví dụ như username thì sẽ chỉ có ký tự từ a đến z hoặc sô hoặc _ – kiểu vậy em sẽ validate được. Còn đối với password thì em có thể validate length thôi chẳng hạn, khi xác thực user em sẽ lấy ra user theo username trước rồi so sánh password sau như vậy sẽ đảm bảo an toàn tuyệt đối em ạ.