You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(security): validate limit() in Update/SoftDelete query builders - #12437
1. New test/github-issues tests 📘 Rule violation⚙ Maintainability⭐ New
Description
New tests were added under test/github-issues/10263 and test/github-issues/10999 instead of the
functional test suite. This conflicts with the guideline to keep issue fixes in test/functional
unless there is a clearly stated reason.
+import { expect } from "chai"+import type { DataSource } from "../../../src"+import {+ closeTestingConnections,+ createTestingConnections,+} from "../../utils/test-utils"+import { Space } from "./entity/Space"++describe("github issues > #10263 closure table should inherit entity schema", () => {+ let dataSources: DataSource[]++ before(async () => {+ dataSources = await createTestingConnections({+ entities: [Space],+ enabledDrivers: ["postgres"],+ schemaCreate: false,+ dropSchema: false,+ })+ })++ after(() => closeTestingConnections(dataSources))++ it("should set the same schema on the closure junction table as the parent entity", () => {+ dataSources.forEach((dataSource) => {+ const spaceMetadata = dataSource.getMetadata(Space)++ expect(spaceMetadata.schema).to.equal("my_schema")+ expect(spaceMetadata.closureJunctionTable).to.not.be.undefined+ expect(spaceMetadata.closureJunctionTable.schema).to.equal(+ "my_schema",+ )+ expect(spaceMetadata.closureJunctionTable.tablePath).to.contain(+ "my_schema",+ )+ })+ })+})
Evidence
PR Compliance ID 3 requires issue-fix coverage to be added/updated in test/functional rather than
adding per-issue tests under test/github-issues without justification; this PR introduces new
per-issue tests in those directories.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
New tests were added under `test/github-issues/...` rather than placing the coverage into `test/functional` (or documenting why a per-issue test is required).
## Issue Context
Compliance prefers functional tests for issue fixes to improve long-term maintainability.
## Fix Focus Areas
- test/github-issues/10263/issue-10263.test.ts[1-37]
- test/github-issues/10999/issue-10999.test.ts[1-42]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. issue-10999 placeholder comment 📘 Rule violation⚙ Maintainability⭐ New
Description
The added line // you can add additional tests if needed is non-actionable boilerplate and
constitutes AI-like noise. This violates the requirement to avoid introducing extra/noisy comments.
PR Compliance ID 4 prohibits adding AI-generated noise and extra comments; the new placeholder
comment provides no value and should not be in merged code.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
A non-actionable placeholder comment was added and should be removed.
## Issue Context
Compliance requires avoiding AI-like boilerplate/noise in code and tests.
## Fix Focus Areas
- test/github-issues/10999/issue-10999.test.ts[41-41]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Limit 0 dropped 🐞 Bug≡ Correctness⭐ New
Description
UpdateQueryBuilder.limit and SoftDeleteQueryBuilder.limit now normalize inputs via Number(), so a
caller-provided numeric string "0" becomes 0, but createLimitExpression uses a truthy check (if
(limit)) and omits LIMIT when the value is 0. This can turn an intended LIMIT 0 safety into an
unbounded UPDATE/SOFT DELETE affecting all matched rows.
The PR changes UpdateQueryBuilder/SoftDeleteQueryBuilder to store a normalized numeric limit
(potentially 0) using validateNumericInput, which converts non-number inputs via Number(). Both
builders’ SQL generation still uses if (limit); when the normalized value is 0, the LIMIT clause
is skipped entirely.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`UpdateQueryBuilder` and `SoftDeleteQueryBuilder` now normalize `limit` using `validateNumericInput()`, which converts non-number inputs using `Number(...)`. This can produce a numeric `0` (e.g., caller passes the numeric string `"0"`).
Both builders generate SQL using `if (limit)` in `createLimitExpression()`, so `0` is treated as “not set” and the `LIMIT` clause is omitted, potentially leading to unbounded UPDATE / SOFT DELETE.
### Issue Context
This is especially risky because the new normalization makes it more likely that user input arrives as a real number (including `0`) rather than a truthy string.
### Fix Focus Areas
- src/query-builder/UpdateQueryBuilder.ts[758-773]
- src/query-builder/SoftDeleteQueryBuilder.ts[560-572]
- (optional for consistency) src/query-builder/UpdateQueryBuilder.ts[429-431]
- (optional for consistency) src/query-builder/SoftDeleteQueryBuilder.ts[398-400]
### Expected change
Update `createLimitExpression()` in both builders to treat `0` as a set limit, e.g.:
- `if (limit !== undefined && limit !== null)` instead of `if (limit)`
This preserves correct behavior for `limit=0` and avoids silently dropping LIMIT.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
View more (2) 4. as any in injection tests 📘 Rule violation⚙ Maintainability
Description
The new tests bypass typing by casting malicious string inputs to any when calling .limit().
This introduces prohibited type-safety bypass noise and can normalize using any instead of
exercising runtime validation via a typed-safe approach.
+ .limit("1; DROP TABLE post" as any)+ }).to.throw(/not a number/)++ expect(() => {+ connection+ .createQueryBuilder()+ .update(Post)+ .set({ title: "test" })+ .limit(10)+ }).to.not.throw()+ })+ })++ it("should not allow non-numeric limit in SoftDeleteQueryBuilder", () => {+ connections.forEach((connection) => {+ expect(() => {+ connection+ .createQueryBuilder()+ .softDelete()+ .from(Post)+ .limit("1; DROP TABLE post" as any)+ }).to.throw(/not a number/)
Evidence
PR Compliance ID 4 forbids introducing any-casts to bypass type checks. The added tests explicitly
use "1; DROP TABLE post" as any in two new .limit(...) calls.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The tests use `as any` casts to pass invalid string values into `.limit()`, which violates the compliance rule against type-bypass noise.
## Issue Context
These tests can still validate runtime rejection of non-numeric limits without introducing `any` casts.
## Fix Focus Areas
- test/other-issues/preventing-injection/preventing-injection.test.ts[232-270]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
5. Zero limit dropped 🐞 Bug≡ Correctness
Description
UpdateQueryBuilder/SoftDeleteQueryBuilder now normalize limit via validateNumericInput(), so a
numeric string like "0" becomes the number 0. Their createLimitExpression() uses if (limit) and
will omit the LIMIT clause for 0, potentially turning an intended LIMIT 0 into an unbounded
update/soft-delete.
limit(limit?: number): this {
- this.expressionMap.limit = limit+ this.expressionMap.limit = this.validateNumericInput("limit", limit)
return this
Evidence
validateNumericInput() calls normalizeNumber(), which converts non-number inputs using Number(...),
so "0" normalizes to 0. Both UpdateQueryBuilder and SoftDeleteQueryBuilder only append LIMIT when
limit is truthy, so a normalized 0 will not produce a LIMIT clause.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`createLimitExpression()` in both `UpdateQueryBuilder` and `SoftDeleteQueryBuilder` uses a truthiness check (`if (limit)`), which skips emitting `LIMIT` when the value is `0`. After this PR, `validateNumericInput()` normalizes numeric strings (e.g. "0") to `0`, making this bug easier to hit and potentially widening an intended no-op (`LIMIT 0`) into an unbounded UPDATE/SOFT DELETE.
### Issue Context
Other parts of the codebase (e.g. select pagination) treat `0` as a set value by checking `!== undefined && !== null` instead of truthiness.
### Fix Focus Areas
- src/query-builder/UpdateQueryBuilder.ts[758-773]
- src/query-builder/SoftDeleteQueryBuilder.ts[560-572]
- test/other-issues/preventing-injection/preventing-injection.test.ts[232-270]
### What to change
- Replace `if (limit)` with an explicit presence check like `if (limit !== undefined && limit !== null)` so `0` still emits `LIMIT 0`.
- Add/extend a test to cover `.limit("0" as any)` (and optionally `.limit(0)`) to ensure the LIMIT clause is not dropped (or at least that behavior is explicitly asserted for these builders).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
alumni
changed the title
Fix/validate limit input v0.3
fix(security): validate limit() in Update/SoftDelete query builders
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of change
Backport of #12436 to v0.3
Pull-Request Checklist
masterbranchFixes #00000tests/**.test.ts)docs/docs/**.md)