Repository navigation
fix(items): add explicit sentinel value for clearing supplier in bulk edit - #4617
Conversation
… edit This fixes a regression introduced in the fix for https://github.com/opensourcepos/opensourcepos/security/advisories/GHSA-49mq-h2g4-grr9 Introduce `Item::CLEAR_SUPPLIER_OPTION = 'NONE'` to distinguish between \"leave supplier_id unchanged\" (empty string) and \"clear supplier_id\" (sentinel). Previously, empty string was ambiguous. - Add `CLEAR_SUPPLIER_OPTION` constant with doc comment explaining intent - Update supplier dropdown to include sentinel as first real option - Shift empty string to mean \"do nothing\" across all bulk edit fields Signed-off-by: Travis Garrison <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughBulk item editing separates unchanged and cleared supplier values. Shared field filtering removes invalid or empty inputs, converts the clear sentinel to ChangesBulk item edit handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant ItemsController
participant Item
participant Database
ItemsController->>Item: filterBulkEditFields(input)
Item-->>ItemsController: filtered bulk-edit fields
ItemsController->>Item: update_multiple(itemIds, fields)
Item->>Database: update permitted fields
Database-->>Item: update result
Item-->>ItemsController: update result
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Cover GHSA-49mq-h2g4-grr9: Item::update_multiple() bypasses model $allowedFields via Query Builder, allowing unintended field writes during bulk edit operations. Signed-off-by: Travis Garrison <[email protected]>
filterBulkEditFields now validates field values before accepting them: - Non-scalar values are rejected (array injection guard) - Price/quantity fields are locale-parsed to floats, invalid strings skipped - Boolean fields must be 0 or 1, other values skipped - supplier_id must be numeric; CLEAR_SUPPLIER_OPTION still nulls it Update tests to assert parsed types (float for prices, int for supplier_id) and replace the fill-all-fields fixture with a realistic input that only covers fields a form would actually submit. Signed-off-by: Travis Garrison <[email protected]>
…ests - Track created supplier person IDs for teardown cleanup - Delete supplier records in tearDown to prevent test pollution - Extract item/supplier creation into reusable helper methods Signed-off-by: Travis Garrison <[email protected]>
Signed-off-by: Travis Garrison <[email protected]>
|
@jekkos I've been plugging away at these advisories so that we can get them all patched and get 3.4.2 out the door. I think that's the only thing blocking 3.4.2. The faster you can do code reviews on these the better. |
Convert Item model, Items controller, and bulk update tests to PSR-compliant camelCase naming per project conventions. - Rename update_multiple to updateMultiple in Item model - Rename local variables (item_data, items_to_update, tax_names, etc.) to camelCase across Items controller and Item model - Update ItemBulkUpdateTest to use new updateMultiple method name - Reorder and update AGENTS.md naming conventions Signed-off-by: Travis Garrison <[email protected]>
Typing these creates an inheritance problem as they are not typed in the parent class. |
…dateTest Rename local variables and property names to camelCase for PSR-12 consistency, matching convention used elsewhere in new test code. Signed-off-by: Travis Garrison <[email protected]>
|
@objecttothis thanks a lot for the extra work, advisories kept coming so I got a bit overwhelmed. @CodeRabbit can you check if we can have similar issue with other field than supplier and do we need sentinel value for those in order to fix? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== Locate relevant files =='
fd -t f . app tests | rg '(^|/)(Items\.php|Item\.php|ItemBulkUpdateTest\.php)$|[Ii]tem.*[Bb]ulk|[Bb]ulk.*[Ii]tem'
printf '%s\n' '== Model and controller outlines =='
ast-grep outline app/Models/Item.php --items all --view expanded || true
ast-grep outline app/Controllers/Items.php --items all --view expanded || true
printf '%s\n' '== Bulk-edit-related references with context =='
rg -n -i -C 4 'bulk.{0,20}(edit|update)|filterBulkEditFields|update_multiple|CLEAR_SUPPLIER_OPTION|supplier_id' app tests
printf '%s\n' '== View/form candidates =='
fd -t f . app | rg -i '(item|items).*\.(php|js)$' | while IFS= read -r file; do
if rg -q -i 'bulk.{0,20}(edit|update)|supplier_id|item_type|tax|category' "$file"; then
echo "--- $file"
rg -n -i -C 3 'bulk.{0,20}(edit|update)|supplier_id|item_type|tax|category' "$file"
fi
doneLength of output: 154946 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== app/Views/items/form_bulk.php =='
cat -n app/Views/items/form_bulk.php
printf '%s\n' '== Item bulk-edit methods and whitelist context =='
rg -n -C 20 'function (filterBulkEditFields|update_multiple)|BULK|bulk.*(field|edit)|supplier_id' app/Models/Item.php
printf '%s\n' '== Items bulk-edit actions =='
rg -n -C 18 'function (bulkEdit|bulkUpdate)|filterBulkEditFields|update_multiple' app/Controllers/Items.php
printf '%s\n' '== Targeted bulk-update test names and assertions =='
rg -n -C 8 'function test|filterBulkEditFields|CLEAR_SUPPLIER_OPTION|supplier_id|tax_|category|description|item_type' tests/Models/ItemBulkUpdateTest.phpLength of output: 37272 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== Supplier options used by bulk edit =='
rg -n -C 10 'CLEAR_SUPPLIER_OPTION|suppliers.*\[|supplier_id.*(bulk|NONE)|bulkEdit' app/Controllers/Items.php app
printf '%s\n' '== Item table schema definitions =='
rg -n -i -C 8 'CREATE TABLE.*items|`supplier_id`|supplier_id|`description`|`category`|`name`|reorder_level|allow_alt_description|is_serialized' \
-g '*.sql' -g '*.php' database app tests
printf '%s\n' '== Item tax bulk update implementation =='
rg -n -C 15 'function save_multiple|save_multiple\(|class Item_taxes|class ItemTaxes' app tests
printf '%s\n' '== Tax table schema definitions =='
rg -n -i -C 8 'CREATE TABLE.*item_taxes|item_taxes.*CREATE|`percent`|`name`' -g '*.sql' -g '*.php' database app testsLength of output: 188926
No additional sentinel is needed for the current fields:
That is not the same regression as
Add a sentinel for You are interacting with an AI system. |
|
@jekkos can you review this PR for me? |
This fixes a regression introduced in the fix for https://github.com/opensourcepos/opensourcepos/security/advisories/GHSA-49mq-h2g4-grr9 Introduce
Item::CLEAR_SUPPLIER_OPTION = 'NONE'to distinguish between "leave supplier_id unchanged" (empty string) and "clear supplier_id" (sentinel). Previously, empty string was ambiguous.CLEAR_SUPPLIER_OPTIONconstant with doc comment explaining intentSummary by CodeRabbit
New Features
Bug Fixes