-
Notifications
You must be signed in to change notification settings - Fork 19
Organization list fix for SCP #793
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: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,4 +142,18 @@ module.exports = { | |||||||||||||||||||||||||||||||||||||||
| .matches(/^[a-zA-Z0-9_]+$/) | ||||||||||||||||||||||||||||||||||||||||
| .withMessage('Each registration code must be alphanumeric with underscores only') | ||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
| list: (req) => { | ||||||||||||||||||||||||||||||||||||||||
| req.checkBody('organization_codes') | ||||||||||||||||||||||||||||||||||||||||
| .optional({ checkFalsy: true }) | ||||||||||||||||||||||||||||||||||||||||
| .custom((value) => { | ||||||||||||||||||||||||||||||||||||||||
| if (!Array.isArray(value)) { | ||||||||||||||||||||||||||||||||||||||||
| throw new Error('organization_codes must be an array') | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+146
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Cap the size of organization_codes to prevent large IN queries Add an upper bound (e.g., 100 items) to avoid excessive Apply this diff: - req.checkBody('organization_codes')
- .optional({ checkFalsy: true })
- .custom((value) => {
- if (!Array.isArray(value)) {
- throw new Error('organization_codes must be an array')
- }
- return true
- })
+ req.checkBody('organization_codes')
+ .optional({ checkFalsy: true })
+ .custom((value) => {
+ if (!Array.isArray(value)) {
+ throw new Error('organization_codes must be an array')
+ }
+ if (value.length > 100) {
+ throw new Error('organization_codes cannot exceed 100 entries')
+ }
+ return true
+ })📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| req.checkBody('organization_codes.*') | ||||||||||||||||||||||||||||||||||||||||
| .optional({ checkFalsy: true }) | ||||||||||||||||||||||||||||||||||||||||
| .matches(/^[a-zA-Z0-9_]+$/) | ||||||||||||||||||||||||||||||||||||||||
| .withMessage('Each organization code must be alphanumeric with underscores only') | ||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
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.
💡 Verification agent
🧩 Analysis chain
Verify tenantCode trust boundary
You’re trusting
params.query.tenantCodedirectly to scope results. Per retrieved learnings, tenant/organization identifiers are typically sourced fromreq.decodedTokenand guaranteed after token validation. Allowing a query override might enable cross-tenant data access unless the controller gates this route to privileged roles.To verify call-sites and access control, run:
If this endpoint is not strictly admin-scoped, prefer deriving tenant from the token instead of a query param, or ignore the query value when a token is present.
🏁 Script executed:
Length of output: 70421
🏁 Script executed:
Length of output: 361
Remove direct query override for tenantCode in organization.list
The
orgService.listmethod is currently trustingreq.query.tenantCode, but the controller computes a safetenantCodefrom the token (and body for admins) without forwarding it. As a result, anyone can supply?tenantCode=…on the URL and scope results to another tenant.• In src/controllers/v1/organization.js around line 119, replace:
with something like:
• In src/services/organization.js (lines 253–260), change the tenant filter to use the token-sourced value instead of the raw query:
—or remove the
params.querybranch entirely and rely solely onparams.decodedToken.tenant_code(with an explicit admin override if needed).This ensures the tenantCode always comes from the validated token (or an explicit, authorized override) rather than an untrusted query parameter.
🤖 Prompt for AI Agents