-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Laravel integration for gksh/bitmask #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The package provides: - A `BitmaskCast` for Eloquent models to seamlessly cast integer values to and from `Bitmask` objects. - Eloquent scopes (`HasBitmaskScopes`) for querying bitmask columns with various conditions (has flag, has all flags, has any flag, etc.). - A `make:bitmask-flags` Artisan command to generate bitmask enum classes. - A `ValidBitmask` validation rule to ensure input values conform to bitmask constraints, optionally tied to an enum. - Blade directives for conditional rendering based on bitmask flags. - Custom Blueprint macros for defining bitmask columns in migrations. - Comprehensive unit tests covering all functionalities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 files reviewed, 6 comments
| { | ||
| $value = maskValue($flag); | ||
|
|
||
| return $query->whereRaw("{$column} & ? = ?", [$value, $value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vulnerability: $column is directly interpolated into raw SQL without sanitization. An attacker could pass malicious input like permissions; DROP TABLE users-- as the column name.
Wrap the column name with backticks or use DB::raw() to prevent injection:
| return $query->whereRaw("{$column} & ? = ?", [$value, $value]); | |
| return $query->whereRaw("`{$column}` & ? = ?", [$value, $value]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Concerns/HasBitmaskScopes.php
Line: 28:28
Comment:
SQL injection vulnerability: `$column` is directly interpolated into raw SQL without sanitization. An attacker could pass malicious input like `permissions; DROP TABLE users--` as the column name.
Wrap the column name with backticks or use `DB::raw()` to prevent injection:
```suggestion
return $query->whereRaw("`{$column}` & ? = ?", [$value, $value]);
```
How can I resolve this? If you propose a fix, please make it concise.| { | ||
| $value = $this->combinedMaskValue($flags); | ||
|
|
||
| return $query->whereRaw("{$column} & ? = ?", [$value, $value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vulnerability: $column needs sanitization.
| return $query->whereRaw("{$column} & ? = ?", [$value, $value]); | |
| return $query->whereRaw("`{$column}` & ? = ?", [$value, $value]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Concerns/HasBitmaskScopes.php
Line: 42:42
Comment:
SQL injection vulnerability: `$column` needs sanitization.
```suggestion
return $query->whereRaw("`{$column}` & ? = ?", [$value, $value]);
```
How can I resolve this? If you propose a fix, please make it concise.| { | ||
| $value = $this->combinedMaskValue($flags); | ||
|
|
||
| return $query->whereRaw("{$column} & ? != 0", [$value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vulnerability: $column needs sanitization.
| return $query->whereRaw("{$column} & ? != 0", [$value]); | |
| return $query->whereRaw("`{$column}` & ? != 0", [$value]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Concerns/HasBitmaskScopes.php
Line: 56:56
Comment:
SQL injection vulnerability: `$column` needs sanitization.
```suggestion
return $query->whereRaw("`{$column}` & ? != 0", [$value]);
```
How can I resolve this? If you propose a fix, please make it concise.| { | ||
| $value = maskValue($flag); | ||
|
|
||
| return $query->whereRaw("{$column} & ? != ?", [$value, $value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vulnerability: $column needs sanitization.
| return $query->whereRaw("{$column} & ? != ?", [$value, $value]); | |
| return $query->whereRaw("`{$column}` & ? != ?", [$value, $value]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Concerns/HasBitmaskScopes.php
Line: 69:69
Comment:
SQL injection vulnerability: `$column` needs sanitization.
```suggestion
return $query->whereRaw("`{$column}` & ? != ?", [$value, $value]);
```
How can I resolve this? If you propose a fix, please make it concise.| { | ||
| $value = $this->combinedMaskValue($flags); | ||
|
|
||
| return $query->whereRaw("{$column} & ? = 0", [$value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vulnerability: $column needs sanitization.
| return $query->whereRaw("{$column} & ? = 0", [$value]); | |
| return $query->whereRaw("`{$column}` & ? = 0", [$value]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Concerns/HasBitmaskScopes.php
Line: 83:83
Comment:
SQL injection vulnerability: `$column` needs sanitization.
```suggestion
return $query->whereRaw("`{$column}` & ? = 0", [$value]);
```
How can I resolve this? If you propose a fix, please make it concise.| "illuminate/support": "^10.0|^11.0|^12.0" | ||
| }, | ||
| "require-dev": { | ||
| "laravel/pint": "^1.18", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laravel/prompts is used in production code (MakeBitmaskFlagsCommand) but listed in require-dev. Move it to require:
| "laravel/pint": "^1.18", | |
| "illuminate/support": "^10.0|^11.0|^12.0", | |
| "laravel/prompts": "^0.1|^0.2|^0.3" |
Prompt To Fix With AI
This is a comment left during a code review.
Path: composer.json
Line: 20:20
Comment:
`laravel/prompts` is used in production code (`MakeBitmaskFlagsCommand`) but listed in `require-dev`. Move it to `require`:
```suggestion
"illuminate/support": "^10.0|^11.0|^12.0",
"laravel/prompts": "^0.1|^0.2|^0.3"
```
How can I resolve this? If you propose a fix, please make it concise.
The package provides:
BitmaskCastfor Eloquent models to seamlessly cast integer values to and fromBitmaskobjects.HasBitmaskScopes) for querying bitmask columns with various conditions (has flag, has all flags, has any flag, etc.).make:bitmask-flagsArtisan command to generate bitmask enum classes.ValidBitmaskvalidation rule to ensure input values conform to bitmask constraints, optionally tied to an enum.Greptile Overview
Greptile Summary
This PR adds Laravel integration for the
gksh/bitmaskpackage, providing Eloquent casts, query scopes, validation rules, Blade directives, and migration helpers for working with bitmask fields.Key Changes:
BitmaskCastfor automatic casting between integers and Bitmask objects in Eloquent modelsHasBitmaskScopestrait with query scopes for filtering records by bitmask flagsValidBitmaskvalidation rule with optional enum-based range checkingmake:bitmask-flagsArtisan command for generating bitmask enum classes@hasBitmaskFlag,@hasAnyBitmaskFlag,@hasAllBitmaskFlags)tinyBitmask,smallBitmask,mediumBitmask,bitmask) for migrationsCritical Issues Found:
HasBitmaskScopesmethods - column names are interpolated without sanitizationlaravel/promptsdependency is inrequire-devbut used in production codearray_sum()used instead of bitwise OR for combining bitmask values (works but semantically incorrect)Confidence Score: 1/5
HasBitmaskScopestrait that could allow attackers to execute arbitrary SQL queries. Additionally, incorrect dependency configuration will cause runtime errors in production environments.src/Concerns/HasBitmaskScopes.php(SQL injection) andcomposer.json(dependency misplacement)Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant App as Laravel Application participant SP as TransistorServiceProvider participant Model as Eloquent Model participant Cast as BitmaskCast participant Scope as HasBitmaskScopes participant DB as Database participant Bitmask as Bitmask Object Note over App,SP: Service Provider Registration App->>SP: boot() SP->>SP: registerCommands() SP->>SP: registerBladeDirectives() SP->>SP: registerValidationRules() SP->>SP: registerBlueprintMacros() Note over Model,Bitmask: Eloquent Cast (Retrieval) Model->>Cast: get(model, key, value, attributes) Cast->>Cast: Check if value is null Cast->>Cast: Convert to int Cast->>Bitmask: Create Bitmask instance based on size Bitmask-->>Model: Return Bitmask object Note over Model,Bitmask: Eloquent Cast (Storage) Model->>Cast: set(model, key, value, attributes) Cast->>Cast: Check value type alt value is Bitmask Cast->>Bitmask: value() Bitmask-->>Cast: Return integer else value is int Cast->>Cast: Cast to int end Cast-->>Model: Return integer for storage Note over Model,DB: Query Scopes App->>Model: whereHasBitmaskFlag('permissions', flag) Model->>Scope: scopeWhereHasBitmaskFlag(query, column, flag) Scope->>Scope: maskValue(flag) Scope->>DB: whereRaw("column & ? = ?", [value, value]) DB-->>App: Return filtered results(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!