ORM Raw Query Injection

Detects raw SQL queries embedded within ORM frameworks that bypass parameterization, reintroducing SQL injection risk.

zakirkun 3ba3912 2 files · 3.6 KB Updated

File contents

ORM Raw Query Injection

Overview

ORM frameworks like SQLAlchemy, Hibernate, Sequelize, and GORM provide parameterized query builders that prevent SQL injection. However, they also expose raw(), execute(), and query() escape hatches that, when used with string concatenation or f-strings, reintroduce SQL injection vulnerabilities.

Remediation

Use the ORM's parameterized query API instead of raw query methods.

Vulnerable (Python/SQLAlchemy):

db.execute(f"SELECT * FROM users WHERE username = '{username}'")

Safe (Python/SQLAlchemy):

db.execute(text("SELECT * FROM users WHERE username = :username"), {"username": username})

zakirkun/ice-tea/tree/main/skills/database/orm-raw-query commit 3ba3912472

Frequently asked questions

npx skillmds@latest add zakirkun/orm-raw-query-injection