Skip to content

Fix: Prevent SQL injection in QueueJobModel priority sorting#94

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix-queuejobmodel-priority-sqli
Open

Fix: Prevent SQL injection in QueueJobModel priority sorting#94
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix-queuejobmodel-priority-sqli

Conversation

@gr8man

@gr8man gr8man commented Jul 8, 2026

Copy link
Copy Markdown

This PR fixes a potential SQL injection vulnerability in the QueueJobModel by properly escaping priority values before using them in CASE and FIELD SQL statements. A unit test was also added to ensure correct behavior.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. Could you please adjust the PR title, description, and commit message to avoid framing this as a security vulnerability?

As discussed, the affected priority list is normally controlled by the application developer/operator through config or CLI, not by untrusted end users in normal usage. This is better described as hardening the database queue ordering logic.

Comment thread src/Models/QueueJobModel.php
Comment on lines +63 to +82
public function testSetPriority(): void
{
$model = model(QueueJobModel::class);
$method = $this->getPrivateMethodInvoker($model, 'setPriority');
$builder = $model->builder();

$result = $method($builder, ['high', 'low']);

$sql = $result->getCompiledSelect();

$this->assertStringContainsString('priority', $sql);
if ($model->db->DBDriver === 'MySQLi') {
$this->assertStringContainsString('FIELD(priority, ', $sql);
} else {
$this->assertStringContainsString('CASE ', $sql);
$this->assertStringContainsString(' WHEN ', $sql);
$this->assertStringContainsString(' THEN ', $sql);
$this->assertStringContainsString(' END', $sql);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test seems a bit weak. It checks that SQL contains CASE/FIELD, but not that dangerous values are escaped or keys are normalized.

@gr8man
gr8man force-pushed the fix-queuejobmodel-priority-sqli branch from cc7c72c to c4536da Compare July 17, 2026 18:20
@gr8man
gr8man requested a review from michalsn July 17, 2026 18:20
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