You increase the order number in the URL by one in a dealer portal, and another dealer’s order opens. This is the most serious security risk in B2B portals: one customer being able to see another customer’s data. “Broken access control” (A01) is first on the OWASP Top 10 list, and in portals it usually shows up in exactly this form. This guide explains how to build authorization architecture at the organization, user and record levels, and the points most often missed in the field.
A three-layer model: organization, role, record
- Organization (tenant) separation: Every user belongs to an organization (dealer, customer, supplier). Every record, such as orders, invoices and quotes, also belongs to an organization. All queries are filtered on the server side by the organization ID in the session.
- Role-based access control (RBAC): What can a user do within the organization? Roles such as administrator, purchaser, accounting and viewer determine action permissions.
- Record- or attribute-based rules: Finer rules where needed: “a purchaser can edit only orders they opened”, “orders over a certain amount require administrator approval”.
The order of the layers matters. The organization filter is at the bottom and no role can pierce it; role permissions only make sense on the organization’s own data. The organization ID is always read from the session, never from a parameter sent by the client. An endpoint that sends an organization_id field in the request body and uses it in the query opens another organization’s door to anyone who changes the ID.
Don’t leave the organization filter up to developers remembering it in every query. A filter applied by default in the data access layer (ORM scope, repository class) prevents a single forgotten WHERE clause from turning into a leak. If PostgreSQL is used, Row-Level Security can enforce the same rule in the database as a second line of defense.
Sample role–permission matrix
| Permission | Organization administrator | Purchaser | Accounting | Viewer |
|---|---|---|---|---|
| Creating orders | Yes | Yes | No | No |
| Approving orders (above threshold) | Yes | No | No | No |
| Viewing price lists | Yes | Yes | Yes | No |
| Invoices and account statements | Yes | No | Yes | No |
| Inviting users | Yes (own organization) | No | No | No |
Users on the company side (sales representatives, customer service) also need a concept of “assigned organizations”: a representative sees only the data of the dealers they’re responsible for.
Check the matrix in code by permission name, not role name. Checks of the form if role == "admin" require changes in dozens of places in the code when a new role is added, and one always gets missed. A permission-based check such as can("order.approve") lets you keep role definitions as data. If there’s a feature allowing the support team to sign in as a user (impersonation), that’s a separate permission too; it should be time-limited, clearly shown on screen and every session logged.
Rules to follow in implementation
- Authorization checks always on the server: Hiding a button in the interface isn’t authorization. Every API endpoint must check that the requested record belongs to the organization in the session and that the user’s role permits the action.
- Avoid predictable IDs: Sequential order numbers can be used in URLs, but without an authorization check they’re never enough on their own; where possible, use UUIDs for externally exposed IDs.
- Default deny: When a new endpoint is added without a permission definition, access should be denied.
- Bulk operations and exports: Excel exports, reports and search endpoints must also go through the same organization filter; leaks most often happen here.
- File access: Files such as invoice PDFs should be served not from a public folder but from an endpoint that checks authorization, or with time-limited signed links.
There are two more leak paths often found in the field. The first is caching: if user- or organization-specific API responses are stored in a CDN or application cache without the organization ID in the key, the price list of the dealer who made the first request goes to the next ones. The second is stale permissions in the session: if role information is embedded in a long-lived token, actions can still be taken with the old permissions after the user’s role is downgraded, until the token expires. Invalidate sessions on role changes or keep token lifetimes short.
Authentication: local accounts, MFA and SSO
For small dealers, email and password accounts can be used together with multi-factor authentication (MFA). Large corporate customers, however, want to sign in with their own identity provider; designing the portal with OpenID Connect (OIDC) support makes it easy to enable SSO per organization. When a user leaves the customer company, their account is also closed in the customer’s identity provider. Design the portal’s account opening, role change and access removal steps in line with the corporate identity and access management process.
SSO verifies identity at sign-in, not the role within the portal. Which organization the email domain from the identity provider maps to, and which role a user is given on first sign-in, must be defined on the portal side; automatically assigning the administrator role on first sign-in is a common design mistake. The default role is the least privileged one. If user accounts need to be provisioned and deprovisioned automatically, SCIM (RFC 7644) support can be considered separately.
Audit log
Who viewed or changed which record, on behalf of which organization, and when? Sign-in attempts, role changes, user invitations, and price and order changes should be logged immutably. These records are needed both for investigating security incidents and for answering the customer’s question “who placed this order?”.
Keeping the audit log in the application’s own database, in a table the application user can delete from, isn’t “immutable”. Send the records to an append-only structure or a separate logging system. Since the records contain personal data, set the retention period from the start too.
Don’t go live without testing
Authorization tests should be part of the automated test suite: with test users from two different organizations, access to the other organization’s record should be attempted on every endpoint and its denial verified. The access control sections of OWASP ASVS provide a good checklist for these tests. An independent security assessment before go-live is recommended.
Testing should cover not only reading but also writing, deleting and exporting. Decide up front whether another organization’s record returns a 404 or a 403; returning a 404 also hides the record’s existence. No new endpoint should be merged without this cross-organization test being written. The rule is simple. No test, no authorization.
Frequently asked questions
How many roles should there be?
As few as possible. Within each organization, 3–5 roles cover most scenarios; exceptions are managed with permission flags rather than roles. When the number of roles grows uncontrollably, access reviews become impossible.
Should dealers be able to add their own users?
Yes, with an organization administrator role and only for their own organization. This reduces the support workload; but the role of added users can’t be higher than the administrator’s role, and actions should be logged.
Is SSO mandatory?
No; large customers may want to sign in with their own identity provider (Entra ID, Okta, etc.). If the portal is designed with OIDC support, SSO can be enabled later per organization; for others, a local account with MFA is used.
To design the permission model of your dealer, customer or supplier portal together, see our B2B dealer and customer portals service.