Repository navigation
Fix SQL injection in search macros, int2str options bug, and upgrade tooling - #60
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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)orderAr()(Macroables::setSearchOrder): UpstreamArabic::arQueryOrderBy()performs no escaping on user input, allowing single quotes in search strings to break out of raw SQL passed toorderByRaw().searchAr()andorderAr(): BothsetSearchWheres()andsetSearchOrder()now build SQL with?placeholders and pass values via Laravel's parameter bindings (whereRaw($sql, $bindings)andorderByRaw($sql, $bindings)), removing reliance on MySQL-specificstrtr()escaping.$field(single or comma-separated, with optionaltable.column) are validated against/^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)?$/(throwingInvalidArgumentExceptionon invalid input) and wrapped using the active Query/Eloquent builder grammar.REGEXP: Emits({$column} LIKE ? AND {$column} REGEXP ?)instead of upstream'sLIKE '...' AND REGEXP '...'.Bug Fixes
2.
ArPhpLaravel::int2str()ignored all optional parameters (src/ArPhpLaravel.php)self::Arabic()returns a freshArabicinstance on every call, sosetNumberFeminine(),setNumberFormat(), andsetNumberOrder()were previously applied to throwaway instances beforeint2str()ran on a new default instance.$arabic = self::Arabic()instance so all parameters take effect.3. Aligned
SearchAr::scopeSearchAr()with thesearchArmacro (src/SearchAr.php)($query, $field, $search)→($query, $search, $field, $mode = 'OR')) and delegated directly toMacroables::setSearchWheres(), matching thesearchArQuery/Eloquent macro andREADME.md.4. Explicit key lookup in
ArPhpLaravel::arSentiment()(src/ArPhpLaravel.php)(float) reset($result) > 0with(bool) ($result['isPositive'] ?? false)to avoid depending on array key order.Tooling, CI & Tests
nunomaduro/larastanwithlarastan/larastan: ^3.0incomposer.jsonandphpstan.neon..github/workflows/phpstan.yml(phpstan.neon.dist→phpstan.neon).tests/arPhpTest.phpandtests/ExampleTest.phpfrom deprecated/** @test */docblocks to PHPUnit 11#[Test]attributes (0 deprecations).int2str()options,arSentiment(),int2indic(),standard(),utf8Glyphs(),plural(),searchAr(),orderAr(), SQL injection payloads, invalid column names, quoted phrases, multi-column queries, empty searches, and theSearchArtrait.Verification
./vendor/bin/phpunit: OK (22 tests, 39 assertions, 0 deprecations)./vendor/bin/phpstan analyse: 0 errors./vendor/bin/pint --test: passedcomposer validate --strict&composer audit: valid, 0 advisories, 0 abandoned packages