---
title: "CWE-566: Authorization Bypass Through User-Controlled SQL Primary Key"
url: https://radicalnotion.ai/cwe/cwe-566
type: cwe
description: "The product uses a database table that includes records that should not be accessible to an actor, but it executes a SQL statement with a primary key that can be controlled by that actor."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-566: Authorization Bypass Through User-Controlled SQL Primary Key

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 8
- **Of those, in CISA KEV:** 0
- **New in 2026:** 3
- **CWE catalog version:** 4.21

## Description

The product uses a database table that includes records that should not be accessible to an actor, but it executes a SQL statement with a primary key that can be controlled by that actor.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Architecture and Design | COMMISSION: This weakness refers to an incorrect design related to an architectural security tactic. |
| Implementation | - |

## Applicable platforms

**Languages:** SQL (Often)

**Technologies:** Database Server (Often)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality, Integrity, Access Control | Read Application Data, Modify Application Data, Bypass Protection Mechanism | When a user can set a primary key to any value, then the user can modify the key to point to unauthorized records. |

## Potential mitigations

### Implementation

Modify the query to include a clause that performs an authorization check, or otherwise ensure that the check is performed before the query is executed.

### Implementation

Assume all input is malicious. Use a standard input validation mechanism to validate all input for length, type, syntax, and business rules before accepting the data. Use an "accept known good" validation strategy.

### Implementation

Use a parameterized query AND make sure that the accepted values conform to the business rules. Construct your SQL statement accordingly.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following code uses a parameterized statement, which escapes metacharacters and prevents SQL injection vulnerabilities, to construct and execute a SQL query that searches for an invoice matching the specified identifier \[1\]. The identifier is selected from a list of all invoices associated with the current authenticated user.

Bad code:

```c#
...
conn = new SqlConnection(_ConnectionString);
conn.Open();
int16 id = System.Convert.ToInt16(invoiceID.Text);
SqlCommand query = new SqlCommand( "SELECT * FROM invoices WHERE id = @id", conn);
query.Parameters.AddWithValue("@id", id);
SqlDataReader objReader = objCommand.ExecuteReader();
...
```

The problem is that the developer has not considered all of the possible values of id. Although the interface generates a list of invoice identifiers that belong to the current user, an attacker can bypass this interface to request any desired invoice. Because the code in this example does not check to ensure that the user has permission to access the requested invoice, it will display any invoice, even if it does not belong to the current user.

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2025-9953 | SQLi in Database Software's Databank Accreditation Software | critical | 9.8 | - | No | 2026-02-19 |
| CVE-2014-0808 | EC-CUBE vulnerable to authorization bypass | critical | 9.1 | - | No | 2014-01-22 |
| CVE-2026-84650 | jenkins: Jenkins: Configuration overwrite via transient field deserialization | high | 8.8 | - | No | 2026-09-02 |
| CVE-2026-85749 | MailWatch: IDOR lets any authenticated user release or delete another tenant's quarantined mail | high | 8.1 | - | No | 2026-10-28 |
| CVE-2025-56556 | Subrion CMS: Authenticated administrators are able to gain escalated access through Run SQL Query tool | medium | 6.5 | - | No | 2025-09-11 |
| CVE-2024-22261 | SQL Injection in Harbor scan log API | medium | 5.5 | - | No | 2024-06-10 |
| CVE-2025-30369 | Zulip allows the deletion of Custom profile fields by administrators of a different organization | low | 2.7 | - | No | 2025-03-31 |
| CVE-2025-30368 | Zulip allows the deletion of organization by administrators of a different organization | low | 2.7 | - | No | 2025-03-31 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-639](https://radicalnotion.ai/cwe/cwe-639) | Authorization Bypass Through User-Controlled Key |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| Software Fault Patterns | Tainted input to variable | SFP25 | - |

## Frequently asked questions

### What is CWE-566?

The product uses a database table that includes records that should not be accessible to an actor, but it executes a SQL statement with a primary key that can be controlled by that actor.

### What CVEs are caused by CWE-566?

8 recorded CVEs are attributed to CWE-566, including CVE-2025-9953, CVE-2014-0808 and CVE-2026-84650.

### How do you prevent CWE-566?

Modify the query to include a clause that performs an authorization check, or otherwise ensure that the check is performed before the query is executed.

### How is CWE-566 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-566?

Exploiting CWE-566 can lead to: Read Application Data, Modify Application Data, Bypass Protection Mechanism.

### Is CWE-566 actively exploited?

8 recorded CVEs are caused by CWE-566; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/566.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-566). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
