Skip to content

Fix SQL injection in search macros, int2str options bug, and upgrade tooling - #60

Merged
atmonshi merged 1 commit into
mainfrom
fix/security-and-bugs
Nov 29, 2026
Merged

atmonshi merged 1 commit into
mainfrom
fix/security-and-bugs

Conversation

@atmonshi

Copy link
Copy Markdown
Member

Summary

This PR resolves security vulnerabilities, functional bugs, and maintenance issues identified in a codebase audit.


Security Fixes

1. Parameterized SQL & column validation in searchAr / orderAr (src/Macroables.php, src/SearchAr.php)

  • Fixed SQL Injection in orderAr() (Macroables::setSearchOrder): Upstream Arabic::arQueryOrderBy() performs no escaping on user input, allowing single quotes in search strings to break out of raw SQL passed to orderByRaw().
  • Parameterized bindings for searchAr() and orderAr(): Both setSearchWheres() and setSearchOrder() now build SQL with ? placeholders and pass values via Laravel's parameter bindings (whereRaw($sql, $bindings) and orderByRaw($sql, $bindings)), removing reliance on MySQL-specific strtr() escaping.
  • Strict column identifier validation & grammar wrapping: Column names passed via $field (single or comma-separated, with optional table.column) are validated against /^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)?$/ (throwing InvalidArgumentException on invalid input) and wrapped using the active Query/Eloquent builder grammar.
  • Fixed missing column name before REGEXP: Emits ({$column} LIKE ? AND {$column} REGEXP ?) instead of upstream's LIKE '...' AND REGEXP '...'.
  • Safe empty-search handling: Whitespace-only or empty search terms return the query untouched instead of generating invalid SQL.

Bug Fixes

2. ArPhpLaravel::int2str() ignored all optional parameters (src/ArPhpLaravel.php)

  • self::Arabic() returns a fresh Arabic instance on every call, so setNumberFeminine(), setNumberFormat(), and setNumberOrder() were previously applied to throwaway instances before int2str() ran on a new default instance.
  • Now reuses a single $arabic = self::Arabic() instance so all parameters take effect.

3. Aligned SearchAr::scopeSearchAr() with the searchAr macro (src/SearchAr.php)

  • Fixed the reversed parameter order (($query, $field, $search) → ($query, $search, $field, $mode = 'OR')) and delegated directly to Macroables::setSearchWheres(), matching the searchAr Query/Eloquent macro and README.md.

4. Explicit key lookup in ArPhpLaravel::arSentiment() (src/ArPhpLaravel.php)

  • Replaced (float) reset($result) > 0 with (bool) ($result['isPositive'] ?? false) to avoid depending on array key order.

Tooling, CI & Tests

  • Replaced abandoned nunomaduro/larastan with larastan/larastan: ^3.0 in composer.json and phpstan.neon.
  • Fixed PHPStan workflow path trigger in .github/workflows/phpstan.yml (phpstan.neon.dist → phpstan.neon).
  • Migrated PHPUnit tests in tests/arPhpTest.php and tests/ExampleTest.php from deprecated /** @test */ docblocks to PHPUnit 11 #[Test] attributes (0 deprecations).
  • Expanded test coverage to cover int2str() options, arSentiment(), int2indic(), standard(), utf8Glyphs(), plural(), searchAr(), orderAr(), SQL injection payloads, invalid column names, quoted phrases, multi-column queries, empty searches, and the SearchAr trait.

Verification

  • ./vendor/bin/phpunit: OK (22 tests, 39 assertions, 0 deprecations)
  • ./vendor/bin/phpstan analyse: 0 errors
  • ./vendor/bin/pint --test: passed
  • composer validate --strict & composer audit: valid, 0 advisories, 0 abandoned packages

@atmonshi
atmonshi merged commit 76d4c86 into main Nov 29, 2026
5 checks passed
@atmonshi
atmonshi deleted the fix/security-and-bugs branch November 29, 2026 08:54
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.

1 participant