Repository navigation
demo(dist2): VG004-VG006 across SQL/Go/Python #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Dist 2: VG004-VG006 | ||
|
|
||
| This demo bundle intentionally triggers: | ||
|
|
||
| - VG004 (unbounded select) | ||
| - VG005 (LIKE with leading wildcard) | ||
| - VG006 (`SELECT ... FOR UPDATE` without `WHERE`) | ||
|
|
||
| Coverage in this bundle: | ||
|
|
||
| - SQL files | ||
| - Go `database/sql` | ||
| - Goqu | ||
| - Python ORM | ||
| - Python non-ORM (`session.execute(text(...))`) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package demo | ||
|
|
||
| import goqulib "github.com/doug-martin/goqu/v9" | ||
|
|
||
| func GoquViolations() { | ||
| _ = goqulib.L("SELECT id, email FROM users WHERE active = true") | ||
| _ = goqulib.L("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _ = goqulib.L("SELECT id FROM users FOR UPDATE") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package demo | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| ) | ||
|
|
||
| func StdViolations(db *sql.DB) { | ||
| ctx := context.Background() | ||
| _, _ = db.QueryContext(ctx, "SELECT id, email FROM users WHERE active = true") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _, _ = db.QueryContext(ctx, "SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _, _ = db.QueryContext(ctx, "SELECT id FROM users FOR UPDATE") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from sqlalchemy import text | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from models import User | ||
|
|
||
|
|
||
| def orm_unbounded_select(session: Session): | ||
| return session.query(User.id, User.email).filter(User.active.is_(True)).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def orm_like_leading_wildcard(session: Session): | ||
| return session.query(User.id).filter(User.email.like("%@example.com")).limit(1).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def orm_select_for_update_no_where(session: Session): | ||
| return session.execute(text("SELECT id FROM users FOR UPDATE")).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from sqlalchemy import text | ||
| from sqlalchemy.orm import Session | ||
|
|
||
|
|
||
| def raw_unbounded_select(session: Session): | ||
| return session.execute(text("SELECT id, email FROM users WHERE active = true")).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def raw_like_leading_wildcard(session: Session): | ||
| return session.execute( | ||
| text("SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1") | ||
| ).all() | ||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| def raw_select_for_update_no_where(session: Session): | ||
| return session.execute(text("SELECT id FROM users FOR UPDATE")).all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT id, email FROM users WHERE active = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT id FROM users WHERE email LIKE '%@example.com' LIMIT 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT id FROM users FOR UPDATE; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [valk-guard] reported by reviewdog 🐶 |
||
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.
VG004: SELECT without LIMIT may return unbounded rows; add LIMIT or FETCH FIRST | Query:
SELECT id, email FROM users WHERE active = true