fix(creature): align table with ac - #3779
Conversation
📝 WalkthroughWalkthroughTwo independent fixes: (1) the ChangesCreatureSpawn id1 → id column rename
Quest preview debounce constant + test timing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.ts`:
- Around line 20-23: The selectQuery method is vulnerable to SQL injection
because the id parameter is directly interpolated into the SQL string using
template literal syntax. Replace the direct interpolation of id in the WHERE
clause with a parameterized query placeholder (such as ?) and pass id as a
separate parameter to the queryService.query method. This will ensure the id
value is properly escaped and treated as data rather than SQL code, preventing
malicious input from altering the query logic.
In `@libs/shared/base-abstract-classes/src/core.mock.ts`:
- Around line 158-160: The selectQuery method directly interpolates the id
parameter into the SQL query string without sanitization, creating a SQL
injection vulnerability. Since id is typed as string or number, validate and
coerce it to a numeric value before using it in the SQL template literal. Use
parseInt or Number() to convert the id to an integer, validate it's a valid
number, and ensure it's safe before inserting it into the SQL query string in
the selectQuery method.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9403f344-665a-4830-aff0-9f0e83882ad3
📒 Files selected for processing (15)
libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.spec.tslibs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.tslibs/features/creature/src/creature-spawn/creature-spawn.integration.spec.tslibs/features/item/src/item-template/item-preview.service.tslibs/features/quest/src/quest-offer-reward/quest-offer-reward.integration.spec.tslibs/features/quest/src/quest-preview/quest-preview.component.tslibs/features/quest/src/quest-request-items/quest-request-items.integration.spec.tslibs/features/quest/src/quest-template-addon/quest-template-addon.integration.spec.tslibs/shared/acore-world-model/src/entities/creature-spawn.type.tslibs/shared/base-abstract-classes/src/core.mock.tslibs/shared/db-layer/src/query/mysql-query.service.spec.tslibs/shared/db-layer/src/query/mysql-query.service.tslibs/shared/sai-editor/src/sai-handler.service.spec.tslibs/shared/sai-editor/src/sai-handler.service.tsvitest.base.config.ts
| selectQuery(id: string | number) { | ||
| return this.queryService.query<CreatureSpawnAddon>( | ||
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id1 = ${id}`, | ||
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`, | ||
| ); |
There was a problem hiding this comment.
Parameterize id in selectQuery to prevent SQL injection.
id accepts string | number and is interpolated directly into SQL. A crafted string (e.g. 1 OR 1=1) can alter the query.
Suggested fix
selectQuery(id: string | number) {
+ const creatureId = Number(id);
+ if (!Number.isInteger(creatureId)) {
+ throw new Error(`Invalid creature id: ${id}`);
+ }
+
return this.queryService.query<CreatureSpawnAddon>(
- `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`,
+ `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${creatureId}`,
);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| selectQuery(id: string | number) { | |
| return this.queryService.query<CreatureSpawnAddon>( | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id1 = ${id}`, | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`, | |
| ); | |
| selectQuery(id: string | number) { | |
| const creatureId = Number(id); | |
| if (!Number.isInteger(creatureId)) { | |
| throw new Error(`Invalid creature id: ${id}`); | |
| } | |
| return this.queryService.query<CreatureSpawnAddon>( | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${creatureId}`, | |
| ); | |
| } |
🧰 Tools
🪛 OpenGrep (1.22.0)
[ERROR] 21-23: SQL query built via string concatenation or template literal passed to query()/execute(). Use parameterized queries instead.
(coderabbit.sql-injection.raw-query-concat-js)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.ts`
around lines 20 - 23, The selectQuery method is vulnerable to SQL injection
because the id parameter is directly interpolated into the SQL string using
template literal syntax. Replace the direct interpolation of id in the WHERE
clause with a parameterized query placeholder (such as ?) and pass id as a
separate parameter to the queryService.query method. This will ensure the id
value is properly escaped and treated as data rather than SQL code, preventing
malicious input from altering the query logic.
| selectQuery(id: string | number) { | ||
| return this.queryService.query( | ||
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id1 = ${id}`, | ||
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`, |
There was a problem hiding this comment.
Sanitize id before building SQL in selectQuery.
Line [160] interpolates id directly into SQL while id is typed as string | number; a crafted string can alter the query. Coerce/validate as numeric before interpolation.
Suggested fix
selectQuery(id: string | number) {
+ const numericId = Number(id);
+ if (!Number.isFinite(numericId)) {
+ throw new Error('Invalid creature id');
+ }
return this.queryService.query(
- `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`,
+ `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${numericId}`,
) as Observable<MockEntity[]>;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| selectQuery(id: string | number) { | |
| return this.queryService.query( | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id1 = ${id}`, | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id}`, | |
| selectQuery(id: string | number) { | |
| const numericId = Number(id); | |
| if (!Number.isFinite(numericId)) { | |
| throw new Error('Invalid creature id'); | |
| } | |
| return this.queryService.query( | |
| `SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${numericId}`, | |
| ) as Observable<MockEntity[]>; | |
| } |
🧰 Tools
🪛 ast-grep (0.43.0)
[error] 158-160: Avoid SQL injection
Context: this.queryService.query(
SELECT a.* FROM creature AS c INNER JOIN creature_addon AS a ON c.guid = a.guid WHERE c.id = ${id},
)
Note: [CWE-89].
(sql-injection-typescript)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@libs/shared/base-abstract-classes/src/core.mock.ts` around lines 158 - 160,
The selectQuery method directly interpolates the id parameter into the SQL query
string without sanitization, creating a SQL injection vulnerability. Since id is
typed as string or number, validate and coerce it to a numeric value before
using it in the SQL template literal. Use parseInt or Number() to convert the id
to an integer, validate it's a valid number, and ensure it's safe before
inserting it into the SQL query string in the selectQuery method.
Source: Linters/SAST tools
related of azerothcore/azerothcore-wotlk#25197
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests