Skip to content

Add Vietnamese SQL vulnerability notes and examples - #2

Open
neotwis wants to merge 2 commits into
mainfrom
codex/tao-file-.md-cho-lo-hong-sql-7s0tqa
Open

Add Vietnamese SQL vulnerability notes and examples#2
neotwis wants to merge 2 commits into
mainfrom
codex/tao-file-.md-cho-lo-hong-sql-7s0tqa

Conversation

@neotwis

@neotwis neotwis commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a focused, Vietnamese-language collection of short notes on common SQL vulnerabilities and operational risks to help teams review and harden database-related code.

Description

  • Expanded README.md with a Vietnamese summary and a linked index of vulnerability topics in the vulnerabilities/ directory.
  • Added new markdown guidance files: vulnerabilities/sql-injection.md, vulnerabilities/blind-sql-injection.md, vulnerabilities/second-order-sql-injection.md, vulnerabilities/excessive-query-complexity.md, vulnerabilities/unbounded-result-sets.md, vulnerabilities/lock-contention-deadlocks.md, and vulnerabilities/missing-rate-limits.md.
  • Each new file includes sections for summary, impact, common causes, mitigations, and illustrative code examples with unsafe and safer patterns (JS snippets using parameterized queries, pagination, rate-limiting, transaction handling, etc.).

Testing

  • No automated tests were added for documentation changes.
  • No repository CI or markdown linting was executed as part of this change.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05832b68b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const where = columns.map((column) => `${column} LIKE ?`).join(' OR ');

const rows = await db.query(
`SELECT id, name, sku FROM products WHERE ${where} LIMIT 50`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle empty allowlist results before querying

When every requested column is absent from SEARCHABLE_COLUMNS (or the client sends only invalid column names), columns becomes empty and this builds SELECT ... WHERE LIMIT 50, so the “safe” example fails with invalid SQL instead of rejecting the request or falling back to a valid predicate. Because this snippet is presented as the safer pattern, it should explicitly handle the zero-column case before constructing the query.

Useful? React with 👍 / 👎.


```js
app.get('/orders', async (req, res) => {
const limit = Math.min(Number(req.query.limit) || 50, 100);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clamp negative limits in the pagination example

For requests such as ?limit=-1, Number(req.query.limit) || 50 evaluates to -1, and Math.min(-1, 100) keeps the negative value, so the supposedly safe pagination example can still emit an invalid/driver-dependent LIMIT ?. Since the text recommends this as the safe version, clamp the lower bound as well as the upper bound before passing it into SQL.

Useful? React with 👍 / 👎.

Comment on lines +55 to +62
await db.beginTransaction();
for (const item of items) {
await db.query(
'UPDATE products SET stock = stock - ? WHERE id = ?',
[item.quantity, item.product_id]
);
}
await db.commit();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Roll back the transaction when updates fail

If any UPDATE rejects after beginTransaction(), this safer deadlock/lock-contention example skips commit() but never calls rollback(), leaving the connection in an open transaction that can hold locks until the pool discards or resets it. Because the section is teaching how to keep transactions short, wrap the transaction body in try/catch and roll back on failure.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant