-
Notifications
You must be signed in to change notification settings - Fork 22.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SQL Injection Web security documentation to the best practices. #37806
Conversation
@@ -81,18 +81,21 @@ SELECT * FROM users WHERE name = 'a';DROP TABLE users; SELECT * FROM userinfo WH | |||
|
|||
The modified statement creates a valid SQL statement that deletes the `users` table and selects all data from the `userinfo` table (which reveals the information of every user). This works because the first part of the injected text (`a';`) completes the original statement. | |||
|
|||
To avoid this sort of attack, you must ensure that any user data that is passed to an SQL query cannot change the nature of the query. One way to do this is to [escape](https://en.wikipedia.org/wiki/Escape_character) all the characters in the user input that have a special meaning in SQL. | |||
To avoid such attacks, the best practice is to use *parameterized queries* (prepared statements). This approach ensures that the user input is treated as a string of data rather than executable SQL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
To avoid such attacks, the best practice is to use *parameterized queries* (prepared statements). This approach ensures that the user input is treated as a string of data rather than executable SQL. | |
To avoid such attacks, the best practice is to use _parameterized queries_ (prepared statements). This approach ensures that the user input is treated as a string of data rather than executable SQL. |
|
||
In the following statement, we escape the **'** character. The SQL will now interpret the name as the whole string in bold (which is a very odd name indeed, but not harmful). | ||
````SQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
````SQL | |
```SQL |
In the following statement, we escape the **'** character. The SQL will now interpret the name as the whole string in bold (which is a very odd name indeed, but not harmful). | ||
````SQL | ||
SELECT * FROM users WHERE name = ? AND password = ?; | ||
```` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
```` | |
``` |
``` | ||
When executing the above query, for example, in Python, we pass the `name` and `password` as parameters, as shown below. | ||
|
||
````Python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
````Python | |
```Python |
|
||
````Python | ||
cursor.execute("SELECT * FROM users WHERE name = ? AND password = ?", (name, password)) | ||
```` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
```` | |
``` |
Preview URLs (comment last updated: 2025-01-27 17:47:11) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks
Np |
Description
Updated SQL Injection Web security documentation to the best practices.
Motivation
These changes ensure that developers are aware of the standard and best practices related to sql injection.
Additional details
None
Related issues and pull requests
Fixes #37783