Python Forum
SQL Injection attacks on Python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL Injection attacks on Python code
#9
Sanitization is hard. Anything short of perfect and you have a vulnerability (and/or you are risking mangling incoming data). What do you do when '*' or similar characters are valid input? Also it's difficult to prove after the fact that the job is sufficient. Placeholders/parameters are much simpler.

Not to say you shouldn't sanitize (that might well be necessary for all sorts of vulnerabilities beyond simple SQL injection). But relying on it when there are better alternatives isn't a good idea.

Don't write your own encryption. Don't rely on sanitization to avoid SQL injection. A (non python oriented) take on this is at https://kevinsmith.io/sanitize-your-inputs/.

See also https://cheatsheetseries.owasp.org/cheat...Sheet.html
Quote:Defense Option 1: Prepared Statements (with Parameterized Queries)

The use of prepared statements with variable binding (aka parameterized queries) is how all developers should first be taught how to write database queries. They are simple to write, and easier to understand than dynamic queries. Parameterized queries force the developer to first define all the SQL code, and then pass in each parameter to the query later. This coding style allows the database to distinguish between code and data, regardless of what user input is supplied.

Prepared statements ensure that an attacker is not able to change the intent of a query, even if SQL commands are inserted by an attacker.
Reply


Messages In This Thread
SQL Injection attacks on Python code - by rob101 - Oct-11-2022, 03:20 PM
RE: SQL Injection attacks on Python code - by bowlofred - Oct-11-2022, 10:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Better Understanding of Security and injection attacks SQLite KevinBrown 1 2,214 Apr-09-2019, 09:45 PM
Last Post: Legomancer
  Sql Injection using python sumandas89 2 3,471 Jan-15-2018, 03:04 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020