Dev.to Security 🔐 Cybersecurity 👁 0 📖 14 min read

Who gets to open this record?

Originally published on Quest Log. A support ticket can belong to a customer, sit in an agent’s queue, and show up in a supervisor’s report. All three people refer to the same ticket. Give them the same permissions and

Originally published on Quest Log.

A support ticket can belong to a customer, sit in an agent’s queue, and show up in a supervisor’s report. All three people refer to the same ticket. Give them the same permissions and you’ve already made a design decision, even if nobody wrote it down. The customer might see an internal note. The agent might download a report that includes another team’s tickets. The supervisor might be able to edit entries that should be read-only.

The rule the server needs is straightforward to say. Which account can take which action on which record, under what conditions? The work is making that answer consistent across the product. A ticket has a detail page, an attachment, an export, and a search result. Each path can disclose some part of the record. Each needs an answer to the same authorization question.

When the server relies on a record identifier without checking the caller’s permission on that record, the resulting weakness is often called insecure direct object reference, or IDOR. The identifier could be a number, a filename, or a random string. The useful question for a developer is what the server does after it receives that identifier. OWASP IDOR prevention

Start with a policy people can argue about

Imagine a support product that serves several organizations. A customer can read tickets they opened and add public replies. An agent can work tickets in a queue they belong to. A supervisor can export records for teams they supervise. The product also retains an archive, where a former team member might still be the named author of a comment.

Those are sample rules. If your product uses a different policy, write that down first. A user interface mockup can tell you that a button exists. It rarely tells you whether a supervisor can export a ticket after the customer closes their account. The engineering team may be able to ship that behavior without a product decision, but someone will still have to explain it later.

A small table works well here. Put actions down the left side and user relationships across the top. Include the ticket owner, another customer in the same organization, an agent in the assigned queue, an agent elsewhere, and an administrator. Fill each cell with a decision or an explicit question. Separate actions that look similar on screen but have different effects.

For example, “view ticket” might mean view the subject, view the public messages, or view the entire record with staff notes. Treat those as different outcomes. “Export tickets” should specify the records and fields included. When someone says “the supervisor can view everything,” ask whether that includes messages from other organizations and attachments the privacy team has placed under restriction. Now you have a policy you can test.

There’s a similar distinction between a role and a relationship. Two people may both be agents. One works a ticket because it belongs to their queue. The other has no reason to open it. A route that checks for an agent role can still get this wrong if it never checks the queue. Scope a permission to the relevant relationship and record state, and document where those facts come from.

Give the server a trustworthy account and scope

Start with the identity the server verified. Load the relevant memberships or delegations from a trusted source, then apply the rule for the action. If the product lets a user switch organizations, confirm their membership in the requested organization before using it as a scope. A label in a URL or a field sent by the browser can tell the server which organization the person selected. The server has to decide whether that selection is permitted.

The query can often do part of the work. A customer view can look up the requested ticket within the tickets that customer is allowed to read. An agent list can start with the queues assigned to the agent. This pattern makes the scope visible in the data access path and avoids retrieving a broad set of records just to discard most of them.

Some permissions are too involved for a single lookup. A delegated reviewer might have access until a deadline, for instance, while a legal hold might change what can be exported. A shared policy function can keep these conditions in one place. The contract should say which identity, action, and record facts it expects. Decide how a missing membership or unavailable policy dependency behaves. A read failure should leave the protected operation denied, with enough internal context for the team to investigate.

A random ID reduces the chance that people can guess references. It also lets you publish links without exposing a simple record sequence. Links can still be copied, forwarded, or included in a report. The server should reach the same permission decision whether the ID is obvious or opaque. OWASP authorization guidance

Follow the ticket into search and export

Search is a good place to look for gaps. A result can disclose the subject of a ticket even when its detail page denies access. A count can reveal that a restricted ticket exists. An autocomplete response might include a name that never appears in the full search page. Define what a caller may search before the query runs, then make sure facets, summaries, and suggestions use the same scope.

Pagination deserves the same attention. If the first page filters by queue, the second page should carry the same authorization context. A cursor can describe where to continue. It should never expand the set of records a caller can see. If access changes between pages, decide how the response should behave and document that choice in the tests.

Consider a team export that runs in the background. The request to start the export needs an authorization check. The worker needs enough trusted context to generate the right subset of rows. The download also needs a policy. A team member might be allowed to request an export on Monday and lose access before the file is ready. Decide what the service should do at each step, including when to delete the artifact.

File links are easy to treat as a detail because they often come from a storage service outside the app. A private attachment still needs the policy that protects the record. If you grant temporary download access, keep the duration and permissions aligned with the sensitivity of the file. Limit where the link is exposed and avoid writing it into general logs. For files that require prompt revocation, consider whether the download needs to go through a service that can check current access.

Caching can produce a similar separation. A response cached under a ticket ID alone is a poor fit if the response includes staff notes for an agent and customer-visible messages for someone else. Review which parts of the response are private and who can reuse them. Then test what happens when users with different permissions view the same record in sequence.

Make update rules as explicit as read rules

A user who can read a ticket may be allowed to edit only their own reply. An agent who can change the ticket status may need a separate permission to move it to a different queue. When a move changes who can read the ticket, the destination deserves its own policy check.

The fields matter as much as the route. Suppose a customer updates the display name on a reply. The handler should know exactly which fields it accepts and apply a rule for each operation that matters. Sending an entire client-supplied object to a generic update helper makes it harder to see which decisions the server has made. Keep the accepted data small enough that a reviewer can verify what changes.

Batch operations are another place where interfaces hide the decision. If someone closes a list of tickets and one ticket falls outside their queue, will the whole operation fail or will the permitted records close? Either behavior can be reasonable if users know what happened. Apply the policy to every selected record and choose the outcome deliberately. Be careful about error messages that disclose information about records the user cannot see.

The timing of the check matters when ownership or queue assignment can change. Imagine the server checks that an agent owns the ticket, then the ticket moves to another queue before the write completes. The application should preserve the intended permission at the point of the write. A transaction, conditional write, or check at the data layer may be appropriate. The right choice depends on how the application stores ownership and how it coordinates updates.

Give permission changes a life cycle

An access rule has a beginning and an end. A contractor joins a support queue for a weekend. An agent moves to a different team. An organization closes its account and needs a copy of its own records. Consider those transitions while deciding what should happen to each route.

Start with the records and permissions that outlive a session. If a person loses membership, what happens to a saved browser page, a queued export, or a link previously issued for an attachment? Those three paths may have different answers. A page can require a new request to show fresh data. A queued export can check whether it can proceed. A link already handed to a user might need to expire or be revoked through a separate mechanism. Write down which behavior you intend for each.

Access sometimes depends on what was true when something happened. For example, a supervisor may need to read reports from a period when they supervised a team. A different product may restrict access to whoever supervises the team now. Both policies can make sense. Store enough history to implement the one you choose, and make the expected behavior clear to the people who administer it.

There’s also a practical question about administrative access. Someone on the support team eventually needs to fix an account assignment or investigate a misplaced record. Give them a specific administrative action with a reason and an audit entry. A broad override that silently makes every lookup succeed is difficult to explain and easy to carry into code paths where it has no place.

Write tests that describe the decision

A test called “returns 200” tells you what happened. A test called “assigned agent can close a ticket in their queue” tells you what the team intended. Name tests after the permission and use fixtures with meaningful relationships.

Start with two customers in one organization, a customer in another, two agents in different queues, and a team supervisor. Add a ticket with a public reply, a staff note, and an attachment. Use the fixtures to exercise the detail view, list, search, update, export, and download paths you ship. Pick the tests that represent different policy decisions. You don’t need every conceivable combination to make the main boundary clear.

For each important permission, include a test that should pass and one that should fail. On a denied write, confirm the protected record stayed unchanged. On a denied read, confirm the response excludes protected fields or file content. On an export, examine the generated rows and columns. An allowed response can still contain too much.

Add a few state changes. Remove the agent from the queue and confirm their next action reflects the change. Move a ticket and check which team can work it afterward. Close a customer account and exercise the policy the product team chose for old records. The fixtures help catch regressions when someone flattens a policy into a convenient role check months later. OWASP authorization regression testing

A fast unit test can cover the policy function. An integration test can show that a real route calls it, uses the correct identity, and applies the expected scope. Both are useful because they answer different questions. Keep at least one test at the boundary where someone can get the data. If all the tests invoke a helper in isolation, a new route can omit the helper and still pass the suite.

Decide what to tell the caller

A denial message should fit the application. In a staff-facing system, a person may already know a ticket exists and need to request access. In a customer-facing system, revealing that another customer's ticket exists may disclose information by itself. Decide which cases can acknowledge the record and which should return the same result as a missing record. Apply that choice to related routes and error types.

The user experience matters here. A person who loses access to a queue may assume the site is broken if their saved links all stop working. A useful general message can point them toward their own ticket list or support. Give the support team an internal reference they can look up where appropriate. Keep the message free of record details that the current caller may not see.

Logs need different care. The team investigating an authorization incident needs the action, decision, time, and relevant identifiers. It rarely needs the complete ticket text or a signed attachment URL. Record a stable reason code so you can distinguish “no membership” from a failed policy dependency. Limit who can read the logs and give sensitive identifiers the same thought you’d give them anywhere else.

A spike in denials can mean many things. A customer might have bookmarked a stale link. A release might have changed an organization assignment. Look for patterns and deployment context before treating a denial count as evidence of an incident. The first useful question is whether the policy behaved as designed. After that, you can ask why so many people reached the boundary.

Review one path end to end

Pick a feature that already exists. Say the support team wants to add a CSV export to the queue page. Walk through it before opening the pull request. The export request arrives under the current account. The server checks whether the account has export permission for the team. The worker queries the records under the same team scope and emits the allowed columns. A successful job writes a private file, and the download checks the current permission or enforces the limited grant your product chose.

Now change the scenario. The team membership expires before download. The queue is empty. The job receives the wrong team context. The supervisor starts a report while a ticket moves to another queue. Ask what the product promises in each case. You may discover that you need to record the scope at submission time, check it again at download time, or describe the report as a snapshot taken at generation. That choice belongs in the feature design.

Before merging, ask someone who didn’t write the handler to trace the same flow. Have them point to the exact lines that determine the caller, scope the records, and authorize the file. If either of you has to infer which policy is active, make it visible in the code or test. A clear policy pays off most when the feature grows and the original author is working on something else.

Start with the route that hands out the data

If the application already has a mix of older and newer features, choose a narrow first pass. Start with a sensitive object and list every place the app returns or changes it. Draw that list from routes, exports, background jobs, and storage links. Then write down the policy for each action and mark which paths already enforce it. The list puts the work in order without forcing a rewrite of every controller at once.

Fix gaps in a way you can verify. Add the test for the intended behavior, make the scoped lookup or policy call explicit, and review the output itself. If the first fix reveals another route with the same problem, decide whether the shared policy can cover it cleanly. Reuse the part that represents the actual permission. Leave response formatting or route-specific behavior where it belongs.

When you finish the first object, use what you learned to review the next one. The hardest permission problems often turn up where teams give the same word different meanings. “Owner” might mean requester in the support app and invoice payer in billing. Carry the method into the next area and write the new policy in that area’s terms. A record ID gives you a place to look. The rule for the action tells you what you can do when you get there.

Make policy changes reviewable

Put the record rule in the pull request description when a change affects access. A reviewer should be able to tell whether it adds a route to an existing permission or creates a new permission. If the export starts including internal notes, make that visible as a policy change. Someone reviewing a CSV formatter may otherwise assume the shape of the output is the only thing under discussion.

When a feature changes who can see older records, include the transition in the decision. If customers can now invite coworkers into a shared account, ask whether those coworkers should automatically see existing tickets and attachments. The choice may depend on what customers were told when they opened the tickets. You may need a migration, a separate setting, or a product decision about the records the feature can cover.

Leave the decision where future reviewers can find it. A short comment near the policy or a test with a clear name can explain a surprising rule. The best evidence is something that changes when the policy does. When a permission starts expanding quietly, a failed test gives the next reviewer a reason to stop and ask who was supposed to get access.

One practical place to start is the next permission change already on the roadmap. Ask the person requesting it to name the new action, the people who gain it, and a nearby case where access should still be denied. Those answers can become acceptance criteria before anyone changes a query.

Inspired by HighOn.Coffee’s article on insecure direct object references.

Action checklist

  • List every route that reads, changes, or exports the record.
  • Write the allowed actions for each role and record relationship.
  • Scope lookups to records the verified account may access.
  • Check permissions on attachments, exports, and cached responses.
  • Test allowed and denied actions with accounts in different scopes.
  • Confirm a denied write leaves the record unchanged.
📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.