<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Penva Security</title>
    <description>The latest articles on DEV Community by Penva Security (@penva_security).</description>
    <link>https://dev.to/penva_security</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263960%2F5ad05787-5daa-4b98-81fd-321342261865.png</url>
      <title>DEV Community: Penva Security</title>
      <link>https://dev.to/penva_security</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/penva_security"/>
    <language>en</language>
    <item>
      <title>How to Test Your Own API for Broken Access Control (Before a Pentester Does)</title>
      <dc:creator>Penva Security</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:10:39 +0000</pubDate>
      <link>https://dev.to/penva_security/how-to-test-your-own-api-for-broken-access-control-before-a-pentester-does-1i8k</link>
      <guid>https://dev.to/penva_security/how-to-test-your-own-api-for-broken-access-control-before-a-pentester-does-1i8k</guid>
      <description>&lt;p&gt;Broken access control is one of the most common serious issues in web apps and APIs. It's #1 in the OWASP Top 10, and in APIs it usually shows up as &lt;strong&gt;BOLA&lt;/strong&gt; (Broken Object Level Authorization): one user can read or change another user's data just by changing an ID.&lt;/p&gt;

&lt;p&gt;The tricky part is that nothing &lt;em&gt;looks&lt;/em&gt; broken. The request succeeds, the response is valid JSON. It's just the wrong user's data. Scanners often miss it for exactly that reason.&lt;/p&gt;

&lt;p&gt;Here's a simple way to check your own API before a pentest.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create two normal users
&lt;/h2&gt;

&lt;p&gt;Make two test accounts with the &lt;strong&gt;same role&lt;/strong&gt;, ideally in &lt;strong&gt;different organizations/tenants&lt;/strong&gt; if your app is multi-tenant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User A → owns order &lt;code&gt;1001&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;User B → owns order &lt;code&gt;2002&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Log in as each and grab their tokens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;TOKEN_A&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"eyJ...userA"&lt;/span&gt;
&lt;span class="nv"&gt;TOKEN_B&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"eyJ...userB"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Request your own object (baseline)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s https://api.example.com/v1/orders/1001 \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN_A"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should get order &lt;code&gt;1001&lt;/code&gt;. Good.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Request the &lt;em&gt;other&lt;/em&gt; user's object
&lt;/h2&gt;

&lt;p&gt;Same token, other user's ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; \
  https://api.example.com/v1/orders/2002 \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN_A"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected:&lt;/strong&gt; &lt;code&gt;403&lt;/code&gt; or &lt;code&gt;404&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Vulnerable:&lt;/strong&gt; &lt;code&gt;200&lt;/code&gt; with order &lt;code&gt;2002&lt;/code&gt;'s data.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Don't stop at GET
&lt;/h2&gt;

&lt;p&gt;Reading data is bad; changing it is worse. Repeat with the methods that modify data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Can User A edit User B's order?&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; -X PATCH \
  https://api.example.com/v1/orders/2002 \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN_A"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"shipping_address":"test"}'&lt;/span&gt;

&lt;span class="c"&gt;# Can User A delete it?&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; -X DELETE \
  https://api.example.com/v1/orders/2002 \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN_A"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only run write/delete tests in a &lt;strong&gt;test or staging environment&lt;/strong&gt;, never against real customer data.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Check the places people forget
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nested routes:&lt;/strong&gt; &lt;code&gt;/orgs/{orgId}/users/{userId}&lt;/code&gt;. Is &lt;code&gt;orgId&lt;/code&gt; checked, or only &lt;code&gt;userId&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IDs in the body&lt;/strong&gt;, not just the URL: &lt;code&gt;{"account_id": 2002}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File and export URLs:&lt;/strong&gt; &lt;code&gt;/files/{id}/download&lt;/code&gt;, &lt;code&gt;/reports/{id}.pdf&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bulk and search endpoints&lt;/strong&gt; that accept a list of IDs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Role changes:&lt;/strong&gt; after a user is demoted, does their old token still work on admin routes?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Fix it in one place
&lt;/h2&gt;

&lt;p&gt;The usual cause is checking &lt;em&gt;authentication&lt;/em&gt; ("is this a valid user?") but not &lt;em&gt;authorization&lt;/em&gt; ("does this user own this object?"). The fix is to scope every lookup to the current user or tenant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ Finds any order by ID&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ✅ Only finds orders that belong to the caller's tenant&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put this in a shared helper or middleware so every new endpoint gets it by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Turn it into a test
&lt;/h2&gt;

&lt;p&gt;Once you've fixed an endpoint, add an automated test: "User A requesting User B's order returns 404". That stops the bug from coming back in the next refactor.&lt;/p&gt;




&lt;p&gt;This won't replace a full pentest (business logic, chained issues and edge cases need a human with context), but it catches the single most common serious API bug in about 20 minutes.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written by the team at &lt;a href="https://penvasecurity.com.au/" rel="noopener noreferrer"&gt;Penva Security&lt;/a&gt;, human-led penetration testing for startups and SaaS teams.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>api</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
