Skip to content

fix(creature): align table with ac - #3779

Merged
Helias merged 2 commits into
masterfrom
align-ac-creature-table
Jun 18, 2026
Merged

fix(creature): align table with ac#3779
Helias merged 2 commits into
masterfrom
align-ac-creature-table

Conversation

@Helias

@Helias Helias commented Jun 17, 2026

Copy link
Copy Markdown
Member

related of azerothcore/azerothcore-wotlk#25197

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed creature spawn data identification and retrieval
    • Corrected vendor cost query resolution for accurate pricing
    • Resolved creature lookup issues in quest and scripting tools
  • Tests

    • Improved async test stability with consistent debounce timing
    • Enhanced test timeout configuration to handle slower CI environments

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Two independent fixes: (1) the CreatureSpawn entity replaces id1/id2/id3 fields with a single id field, and all SQL queries referencing c.id1 are corrected to c.id across five services with their tests updated; (2) the hard-coded 300 ms debounce value in QuestPreviewComponent is extracted as QUEST_PREVIEW_DEBOUNCE_TIME, used in three integration specs for precise async timing, and the global Vitest testTimeout is raised to 15 s.

Changes

CreatureSpawn id1 → id column rename

Layer / File(s) Summary
CreatureSpawn entity type update
libs/shared/acore-world-model/src/entities/creature-spawn.type.ts
CREATURE_SPAWN_ID/CREATURE_SPAWN_ID_2 constants updated to 'id'/'guid'; id1, id2, id3 fields replaced by a single id field.
SQL service fixes (c.id1 → c.id)
libs/shared/db-layer/src/query/mysql-query.service.ts, libs/shared/sai-editor/src/sai-handler.service.ts, libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.ts, libs/features/item/src/item-template/item-preview.service.ts, libs/shared/base-abstract-classes/src/core.mock.ts
Corrects the column reference from c.id1 to c.id in all SQL-generating services: getCreatureNameByGuid, getName() (SAI), selectQuery (creature-spawn-addon), getItemExtendedCostFromVendor, and the mock service.
Test alignment for id rename
libs/shared/db-layer/src/query/mysql-query.service.spec.ts, libs/shared/sai-editor/src/sai-handler.service.spec.ts, libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.spec.ts, libs/features/creature/src/creature-spawn/creature-spawn.integration.spec.ts
All spec files updated to expect c.id in SQL strings; the integration spec fully re-seeded to use id instead of id1, covering all CRUD scenarios (add, edit, delete, duplicate, MapSelector).

Quest preview debounce constant + test timing

Layer / File(s) Summary
Export QUEST_PREVIEW_DEBOUNCE_TIME constant
libs/features/quest/src/quest-preview/quest-preview.component.ts
Adds exported constant QUEST_PREVIEW_DEBOUNCE_TIME = 300 and replaces the inline 300 in the valueChanges$() debounce call.
Integration test timing and Vitest timeout
libs/features/quest/src/quest-offer-reward/quest-offer-reward.integration.spec.ts, libs/features/quest/src/quest-request-items/quest-request-items.integration.spec.ts, libs/features/quest/src/quest-template-addon/quest-template-addon.integration.spec.ts, vitest.base.config.ts
Three quest integration specs import and use QUEST_PREVIEW_DEBOUNCE_TIME with page.fixture.whenStable() for deterministic preview assertions; vitest.base.config.ts sets testTimeout to 15_000.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity-hop, the columns got right,
id1 was wrong — now id shines bright!
The debounce time named, no magic number hides,
The tests tick precisely with confident strides.
Fifteen-second timeout, for CI's slow days —
A bunny thumps proudly in well-structured ways! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix(creature): align table with ac' is vague and incomplete, using the abbreviation 'ac' without clarity. While it references a real change (creature table alignment), the title does not clearly convey what 'ac' means or the specific nature of the alignment. Expand the title to be more specific and complete, e.g., 'fix(creature): align creature_spawn table with AzerothCore' or similar, to clearly indicate what is being aligned and with what.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch align-ac-creature-table

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c11981 and 38d22d2.

📒 Files selected for processing (15)
  • libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.spec.ts
  • libs/features/creature/src/creature-spawn-addon/creature-spawn-addon.service.ts
  • libs/features/creature/src/creature-spawn/creature-spawn.integration.spec.ts
  • libs/features/item/src/item-template/item-preview.service.ts
  • libs/features/quest/src/quest-offer-reward/quest-offer-reward.integration.spec.ts
  • libs/features/quest/src/quest-preview/quest-preview.component.ts
  • libs/features/quest/src/quest-request-items/quest-request-items.integration.spec.ts
  • libs/features/quest/src/quest-template-addon/quest-template-addon.integration.spec.ts
  • libs/shared/acore-world-model/src/entities/creature-spawn.type.ts
  • libs/shared/base-abstract-classes/src/core.mock.ts
  • libs/shared/db-layer/src/query/mysql-query.service.spec.ts
  • libs/shared/db-layer/src/query/mysql-query.service.ts
  • libs/shared/sai-editor/src/sai-handler.service.spec.ts
  • libs/shared/sai-editor/src/sai-handler.service.ts
  • vitest.base.config.ts

Comment on lines 20 to 23
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}`,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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.

Comment on lines 158 to +160
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}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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

@Helias
Helias merged commit 100f966 into master Jun 18, 2026
14 checks passed
@Helias
Helias deleted the align-ac-creature-table branch June 18, 2026 09:11
@TheSCREWEDSoftware TheSCREWEDSoftware mentioned this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants