-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/transaction itens user validation #108
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?
Feature/transaction itens user validation #108
Conversation
Code Review SummaryThe pull request primarily focuses on enhancing the 🚀 Key Improvements
💡 Minor Suggestions
🚨 Critical Issues
|
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.
Review complete. See the overview comment for a summary.
'description' => 'nullable|string', | ||
'datetime' => ['nullable', new Iso8601DateTime], | ||
'created_at' => ['nullable', new Iso8601DateTime], | ||
'group_id' => 'nullable|integer|exists:groups,id', |
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.
The party_id
validation in the update
method currently uses a simple exists
rule, which means any party_id
existing in the database would be considered valid. This could allow a user to link a transaction to a party belonging to another user, leading to a security vulnerability and data integrity issue. This should mirror the more secure validation implemented in the store
method.
'group_id' => 'nullable|integer|exists:groups,id', | |
'party_id' => ['nullable', 'integer', Rule::exists('parties', 'id')->where(function ($query) { $query->where('user_id', auth()->user()->id); })], |
'datetime' => ['nullable', new Iso8601DateTime], | ||
'created_at' => ['nullable', new Iso8601DateTime], | ||
'group_id' => 'nullable|integer|exists:groups,id', | ||
'party_id' => 'nullable|integer|exists:parties,id', |
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.
Similar to party_id
, the wallet_id
validation in the update
method lacks user-specific scope. This could enable a user to associate a transaction with a wallet that does not belong to them. It is crucial to apply the same secure exists
validation with a user_id
scope as introduced in the store
method to prevent unauthorized data manipulation.
'party_id' => 'nullable|integer|exists:parties,id', | |
'wallet_id' => ['nullable', 'integer', Rule::exists('wallets', 'id')->where(function ($query) { $query->where('user_id', auth()->user()->id); })], |
'type' => 'required|string|in:income,expense', | ||
'description' => 'nullable|string', | ||
'datetime' => ['nullable', new Iso8601DateTime], | ||
'created_at' => ['nullable', new Iso8601DateTime], |
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.
The group_id
validation in the update
method suffers from the same vulnerability as party_id
and wallet_id
. Without scoping the exists
rule to the authenticated user's groups, a malicious user could link their transaction to another user's group. Update this validation rule to include the user_id
check for enhanced security.
'created_at' => ['nullable', new Iso8601DateTime], | |
'group_id' => ['nullable', 'integer', Rule::exists('groups', 'id')->where(function ($query) { $query->where('user_id', auth()->user()->id); })], |
'is_recurring' => 'nullable|boolean', | ||
'recurrence_period' => 'nullable|string|in:daily,weekly,monthly,yearly', | ||
'recurrence_interval' => 'nullable|integer|min:1', | ||
'recurrence_ends_at' => ['nullable', 'date', 'after:today', new Iso8601DateTime], |
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.
The validation for categories.*
in the update
method also needs to be updated to ensure that users can only associate transactions with categories they own. Failing to do so opens a potential security loophole where a user could link to categories belonging to other users. Apply the Rule::exists
with the user scope, consistent with the store
method's implementation.
'recurrence_ends_at' => ['nullable', 'date', 'after:today', new Iso8601DateTime], | |
'categories.*' => ['integer', Rule::exists('categories', 'id')->where(function ($query) { $query->where('user_id', auth()->user()->id); })], |
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.
Hi @Denjiwe thanks for submitting a PR. We appreciate your contributions.
Please kindly address the following issues:
- Run
php artisan test
locally and ensure all the tests pass, then update the PR - We follow the Conventional Commits Specification for our commit messages. Please rename your commits to follow the rules outlined here
Feel free to reply here if you need any help.
This change resolves #99 by using a Illuminate\Validation\Rule validation, checking whether the given group, party, wallet or categories belong to the authenticated user.