---
name: broken-access-control
description: Active authorization and IDOR testing that replays already-captured requests with swapped identities and incremented numeric object-ids, using response length/status diffs to flag privilege escalation. Use when testing broken access control, IDOR, or whether a low-priv user can reach privileged data.
---

## Contents
- Scope & authorization
- Methodology (baseline, identity-swap, numeric IDOR)
- Runnable snippets
- IDOR numeric-parameter wordlist
- Thresholds (carry these exactly)
- Output

## Scope & authorization

Only run against an application the user owns or is contractually engaged to test. This is an ACTIVE, aggressive check: it re-sends real requests to the target under different identities and with mutated object-ids, so it creates traffic, may read or touch other users' data, and can trip rate-limits or alerts. Use a staging environment or a maintenance window where you can, keep the identities and object-ids to accounts you control, and stop if you start returning data that clearly belongs to real third parties. If scope is unclear, ask before replaying.

Two things must exist before you start:
1. A capture of the target's traffic taken as a **privileged / higher-role user** (from a proxy, HAR export, or your own request log). Each captured request gives you the method, URL, headers, query params, cookies, and body.
2. At least one **second identity** to replay under - a lower-privileged user's session, and/or the unauthenticated (no-token, no-cookie) state. An identity is either a cookie (`name=value`) or a bearer token (`Authorization: Bearer ...`).

This skill covers authorization replay and numeric IDOR on already-captured requests. It does not fuzz for hidden endpoints, mutate non-numeric/UUID object references, or bypass auth at the token layer (JWT tampering, session fixation) - note those as unrun if the target warrants a deeper pass.

## Methodology (run in order; each step is a check with a result state)

1. **Inventory the capture.** From the privileged capture, list each request as its parts: method, full URL, headers, query params, cookies, body. These are the units you replay; you never craft new endpoints, only re-send captured ones under new conditions.

2. **Baseline each request as the privileged user.** Re-send it exactly as captured and record `status_code` and response body length. This is the reference every swapped-identity and mutated-id response is compared against, and it confirms the request still works before you draw conclusions from a difference.

3. **Swap identity, replay unchanged (authorization check).** For every captured request, replace only the identity - drop in each second identity's cookie or `Authorization` header in place of the privileged one, leaving method, URL, params, and body identical. Compare each replay's `(status_code, length)` to the privileged baseline. Report a finding when a lesser or unauthenticated identity returns a **success status with a body within 50 bytes of the privileged length** (i.e. `abs(length_diff) <= 50` and no status change) - the low-priv session is being served the privileged response. The source's own trigger is the inverse framing: it flags a pair as differing when `length_diff > 50` or the status differs, so a *non*-differing successful pair across two different identities is the access-control failure.

4. **Find numeric object-id params.** In each captured request's query params, match parameter names against the IDOR wordlist below. Keep only params whose value parses as an integer - these are the candidate direct object references.

5. **Baseline the id param.** Re-send the request with its original numeric id (under the identity that legitimately owns that object) and record `baseline_status` (`"<code> <reason>"`) and `baseline_body_len` (length of the parsed JSON response). Skip the param if the response is not JSON or the length is zero - there is nothing to compare.

6. **Increment the id, twice (IDOR check).** Send the same request twice more, changing only that one param: once at `original + 1` (`first_attempt_size_increase = 1`), once at `original + 100` (`second_attempt_size_increase = 100`). Record status and JSON length for each. Two offsets cover both a densely-packed id space (neighbour exists at +1) and a sparser one (+100 lands on another live object).

7. **Decide IDOR.** Report a finding when the **+1 attempt returns the same status as the baseline** AND **either mutated attempt's JSON length differs from the baseline by at least `response_body_length_diff = 3`**. Same success status across a different id means the object still resolves under your identity; a body-length difference of >= 3 means you got a *different* object's data rather than an empty/error shell. Same status with a near-identical length is the ambiguous "same template, maybe empty" case and is not reported on its own.

8. **Cross the two checks.** The strongest finding is a captured request where an id-param increment (steps 4-7) succeeds *and* the same request replays successfully under a lower-privileged or unauthenticated identity (step 3): an object reference that is both enumerable and unprotected by the session.

## Runnable snippets

Set the target and the privileged identity once. `PRIV_COOKIE`/`PRIV_AUTH` come from your privileged capture; `LOW_COOKIE`/`LOW_AUTH` are the second identity; empty strings are the unauthenticated case.

```bash
BASE="https://TARGET"
PRIV_COOKIE="session=PRIV_SESSION_VALUE"
PRIV_AUTH="Authorization: Bearer PRIV_TOKEN"
LOW_COOKIE="session=LOW_SESSION_VALUE"
LOW_AUTH="Authorization: Bearer LOW_TOKEN"
```

```bash
# 2 baseline a captured request as the privileged user (status + body length)
curl -sk -o /dev/null -w '%{http_code} %{size_download}b\n' \
  -H "$PRIV_AUTH" -b "$PRIV_COOKIE" "$BASE/api/report?client_id=1024"

# 3 authorization check: replay the SAME request under each identity, compare
REQ="/api/report?client_id=1024"
for id in "priv:$PRIV_AUTH:$PRIV_COOKIE" "low:$LOW_AUTH:$LOW_COOKIE" "anon:::"; do
  name="${id%%:*}"; rest="${id#*:}"; auth="${rest%%:*}"; cook="${rest#*:}"
  printf '%-5s ' "$name"
  curl -sk -o /dev/null -w '%{http_code} %{size_download}b\n' \
    ${auth:+-H "$auth"} ${cook:+-b "$cook"} "$BASE$REQ"
done
# finding: a lesser/anon identity returns a success code with size within ~50b of priv
```

```python
# 4-7 numeric IDOR: replay one captured request three times, mutating one id param
import json, urllib.request, urllib.parse, ssl

ctx = ssl.create_default_context(); ctx.check_hostname = False; ctx.verify_mode = ssl.CERT_NONE

NUMERIC_IDOR_PARAMS = {
    "client_id", "clientId", "clientid", "client",
    "user_id", "userId", "userid", "user",
    "document_id", "documentId", "documentid", "document",
    "account", "account_id", "accountId", "accountid",
    "project", "project_id", "projectId", "projectid",
    "report_id", "reportId", "reportid", "report",
    "file_id", "fileId", "fileid", "file",
}
RESPONSE_BODY_LENGTH_DIFF = 3
FIRST_ATTEMPT_SIZE_INCREASE = 1
SECOND_ATTEMPT_SIZE_INCREASE = 100

METHOD  = "GET"
URL     = "https://TARGET/api/report"
HEADERS = {"Authorization": "Bearer PRIV_TOKEN", "Cookie": "session=PRIV_SESSION_VALUE"}
PARAMS  = {"client_id": "1024"}
BODY    = None

def send(params):
    qs = urllib.parse.urlencode(params)
    url = f"{URL}?{qs}" if qs else URL
    data = BODY.encode() if isinstance(BODY, str) else BODY
    req = urllib.request.Request(url, data=data, method=METHOD, headers=HEADERS)
    with urllib.request.urlopen(req, context=ctx) as r:
        raw = r.read()
        try:
            body_len = len(json.loads(raw))
        except Exception:
            body_len = None
        return f"{r.status} {r.reason}", body_len

for key, val in list(PARAMS.items()):
    if key not in NUMERIC_IDOR_PARAMS:
        continue
    try:
        base_val = int(val)
    except ValueError:
        continue
    base_status, base_len = send({**PARAMS, key: base_val})
    if not base_len:
        continue
    a1_status, a1_len = send({**PARAMS, key: base_val + FIRST_ATTEMPT_SIZE_INCREASE})
    a2_status, a2_len = send({**PARAMS, key: base_val + SECOND_ATTEMPT_SIZE_INCREASE})
    same_status = a1_status == base_status
    len_moved = (a1_len is not None and abs(base_len - a1_len) >= RESPONSE_BODY_LENGTH_DIFF) or \
                (a2_len is not None and abs(base_len - a2_len) >= RESPONSE_BODY_LENGTH_DIFF)
    if same_status and len_moved:
        print(f"IDOR: parameter {key}={base_val} seems iterable at {URL}")
```

## IDOR numeric-parameter wordlist

Match captured query-param names against this set; keep only values that parse as integers. It is the union of the two source checks plus their case/underscore enrichment (each `snake_case` seed also yields its `camelCase`, `flatcase`, and bare-prefix forms):

```
client_id, clientId, clientid, client
user_id, userId, userid, user
document_id, documentId, documentid, document
account, account_id, accountId, accountid
project, project_id, projectId, projectid
report_id, reportId, reportid, report
file_id, fileId, fileid, file
```

## Thresholds (carry these exactly)

| Constant | Value | Meaning |
|---|---|---|
| Authorization length tolerance | 50 bytes | Two identities whose responses differ by more than 50 bytes (or in status) are treated as *different*; a successful pair within 50 bytes is the access-control finding. |
| `response_body_length_diff` | 3 | Minimum JSON-length delta between the baseline object and a mutated-id object to count the id as iterable. |
| `first_attempt_size_increase` | 1 | First id offset (adjacent object). |
| `second_attempt_size_increase` | 100 | Second id offset (sparse id space). |

## Output

Finish with a `request / check / result` ledger over the captured requests you replayed, then a one-line verdict:
- **Clean** - every captured request re-authorized correctly (lesser/anon identities were rejected or served a materially different response) and no numeric id param proved iterable.
- **Broken access control** - name the failing request, the check that caught it (identity-swap, id-increment, or both), the identity/id that succeeded, and the observed status/length pair versus the privileged baseline. Fix: enforce per-object ownership checks server-side on every request (never trust a client-supplied id or the mere presence of a valid session), and return 403/404 uniformly so length and status do not leak object existence.

Report each captured request's true status - replayed or not-run - so coverage is honest; never present an unrun request as clean.
