forked from inventree/InvenTree
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(backend): add stock reconciliation API endpoint for cycle counting #2
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
Open
hugbubby
wants to merge
1
commit into
master
Choose a base branch
from
test-idor-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Missing Authorization in Stock Reconciliation (Severity: LOW)
Insecure direct object references allow unauthorized users to adjust stock items. The stocktake method in
serializers.pyperforms adjustments without verifying the user's permissions for each individual stock item, which could lead to unauthorized modifications of inventory data.View details in ZeroPath
Suggested fix
Unable to apply as inline suggestion. Download .diff and apply from repo root with
git apply 64d56011.diffThere 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.
What specific data can a user adjust, here?
Uh oh!
There was an error while loading. Please reload this page.
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.
In this code path, the user can adjust stock item quantities during reconciliation. Specifically, the serializer iterates stock items and calls
stock_item.stocktake(counted, request.user, …)without a per‑item permission check, which records an adjustment for that stock item’s quantity (and related stocktake metadata like notes). So an unauthorized user could modify the inventory quantity for any targetedStockItemin the reconciliation payload.If you want, I can trace the exact request fields (
counted, item IDs, etc.) from the serializer to confirm the full set of mutable fields in this operation.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.
Are there any prerequisites to hitting this endpoint? Any roles/permissions required?
Uh oh!
There was an error while loading. Please reload this page.
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.
From the issue context, the only guarantee here is that
request.userexists (so the endpoint is authenticated), but there’s no per‑item authorization check before callingstock_item.stocktake(...)inserializers.py:1989–1993. That means any authenticated user who can reach the stock reconciliation endpoint can adjust stock items they don’t own/aren’t authorized for, unless upstream view permissions block them.I don’t see explicit endpoint-level permission requirements in the issue data. If you can point me to the specific view/action (e.g., DRF viewset/route for stock reconciliation), I can verify the exact permission classes and whether the endpoint requires a specific role (e.g.,
stock.change_stockitem).In this PR, the recommended fix is to enforce:
(or the new
stock_item.check_ownershippath noted in the assessment). This makes the endpoint safe even if the endpoint-level permissions are broad.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.
Cool, just checked in, and this app isn't actually deployed yet. Can you mark this as an accepted risk for now?
Uh oh!
There was an error while loading. Please reload this page.
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.
Status updated to ACCEPTED_RISK for issue
64d56011-8f11-4c58-9852-78d368101b31with the noted reason (app not deployed yet).If/when deployment is planned, I recommend revisiting and either patching or moving it back to review.