IDOR

Source-reviewed lab

One valid login. Three account records. A profile ID that the server accepts without asking whether it belongs to you. Authentication works; object-level authorization is missing.

Broken access controlPHP 8.2SQLite / PDOSession authenticationCWE-639Static review only
  1. 1. Establish identityjohn → session user_id = 1The supplied login creates a server-side session.
  2. 2. Choose an objectprofile.php?id=3The URL selects a different account record.
  3. 3. Missing permission gateviewer ID ≠ requested IDNothing rejects the cross-account lookup.
  4. 4. Disclose the recordadmin profile + flagThe viewer remains John, even while reading admin data.
The trust boundary is between the authenticated viewer and the requested database row. A valid session is not permission to read every profile.

The scenario

Acme Corp's Customer Portal lets employees log in and read their account details. The intended starting account is john, and a successful login redirects to profile.php?id=1. The profile contains an account ID, username, email, and account type.

The vulnerable endpoint only checks whether a session exists. It then looks up whichever positive numeric ID came from the URL. Changing the reference from John's record to Jane's or the admin's crosses an account boundary without changing the login.

What was reviewed—and what was not run

The PHP, CSS, Docker configuration, README, hidden text clues, and an existing text extraction of the two-page PDF were read. No PHP file, initializer, build script, container, lab, or HTML page was executed or opened in a browser. All outcomes below are source-derived, not captured HTTP responses.

Your starting point

Credentials supplied by the README and PDF
Username: john
Password: password123
Documented lab address: http://localhost:8080

These are intentionally published training credentials. You do not need the admin password, a forged session cookie, SQL injection, or a brute-force tool to understand this solve.

What a complete solve means

  • Identify the requested object: a row in the users table.
  • Show where the URL's id reaches the database lookup.
  • Distinguish the viewer's session identity from the record being displayed.
  • Explain why changing 1 → 2 exposes another ordinary user's profile.
  • Explain why changing 1 → 3 reveals the seeded flag to John.
  • Propose server-side authorization and negative regression tests.

The important distinction

Authentication answers “Who is making the request?” Authorization answers “May this user access this particular object?”

The important limit

This endpoint demonstrates unauthorized reads. The supplied code does not establish account takeover, password changes, or admin action access.

Reveal the source-defined flag and target profile

The initializer plants this value on the third account in a freshly created database. It is not printed in the README or the PDF and was not retrieved from a running service here.

Seeded flag · init_db.php, line 73
FLAG{idor_access_control_failure}

The intended target is profile.php?id=3 while authenticated as John (ID 1) or Jane (ID 2). The template hides the flag when the flag owner views their own profile.

How the flaw works

Checked against PHP source

A safe SQL query can still answer an unauthorized question. The bug is not how the database parses the ID—it is the missing decision about who may request it.

1. Login establishes the viewer

login.php accepts POST requests, looks up the supplied username with a prepared statement, and checks the stored password hash with password_verify. On success, it stores the account's ID and username in the session.

login.php · lines 30–37
if ($user && password_verify($password, $user['password'])) {
    // Store only the user's ID and username in the session
    $_SESSION['user_id']   = $user['id'];
    $_SESSION['username']  = $user['username'];

    // Redirect to the profile page using the numeric ID in the URL
    header("Location: profile.php?id=" . $user['id']);
    exit;
}

The URL does not establish identity. The server-side session does. Asking for ?id=3 does not assign 3 to $_SESSION['user_id'].

2. The profile gate checks login, not ownership

profile.php · lines 35–44, excerpt
session_start();
require_once 'db.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: index.php");
    exit;
}

This is a real authentication gate. An unauthenticated request exits before the profile query. But an authenticated John, Jane, or admin passes the same gate regardless of which row they request.

3. A client-controlled ID chooses the row

profile.php · lines 51–56
$requestedId = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($requestedId <= 0) {
    // Fall back to the logged-in user's own profile
    $requestedId = $_SESSION['user_id'];
}

The cast converts the query-string input to an integer. Missing or nonpositive values fall back to the viewer's own ID. Positive values remain free to identify a different account.

Integer conversion is not a permission check and is not strict format validation. Whether the value is a well-formed integer and whether the viewer may access that integer's record are separate questions.

4. The prepared statement is globally scoped

profile.php · lines 70–74
try {
    $db   = getDB();
    $stmt = $db->prepare("SELECT id, username, email, role, flag FROM users WHERE id = :id");
    $stmt->execute([':id' => $requestedId]);
    $profile = $stmt->fetch();

The query binds a value rather than concatenating SQL. That addresses SQL-injection risk in this lookup, but the query searches all users by the supplied key. It never restricts the result to an account the viewer is allowed to read.

Data flow: $_GET['id'] → $requestedId → :id → users row → HTML. The session is checked for existence, but not used to authorize the selected row.

5. Ownership is calculated but not enforced

profile.php · line 81
$isOwnProfile = ((int)$_SESSION['user_id'] === $requestedId);

The application already has enough information to detect a cross-account view. It uses that comparison for flag presentation, not to deny access. The ordinary profile fields render whenever $profile contains a record.

6. The flag rewards a cross-account read

profile.php · line 169, condition
if (!empty($profile['flag']) && !$isOwnProfile):

Two conditions must hold: the selected record must contain a nonempty flag, and the viewer must not own that record. The seeded admin record meets the first condition; John's session requesting ID 3 meets the second.

Logging in as admin and viewing ID 3 makes $isOwnProfile true, so the flag is hidden. That is an intentional challenge rule, not production access control. Hiding a flag on the owner's page does not stop unauthorized access to other fields.

Source-defined behavior for the fresh seed

Expected application behavior, not responses observed during this review.
ViewerRequestRecord / resultFlag row
No session?id=3Redirect to index.php; no profile lookup.Not rendered
John (1)?id=1John's own profile.Absent: no seeded flag
John (1)?id=2Jane's profile, with John still logged in.Absent: no seeded flag
John (1)?id=3Admin's profile, with John still logged in.Rendered
Jane (2)?id=3Admin's profile, with Jane still logged in.Rendered
Admin (3)?id=3Admin's own profile.Hidden by owner condition
John (1)No id, 0, or negative IDFalls back to John's own profile.Absent
John (1)?id=999“No account found for the requested ID.”Absent

No admin session and no password disclosure

The selected record's role drives an “Admin” display badge; it does not grant permissions to the viewer. The profile query does not select the password column. This source establishes profile and flag disclosure, not an admin login or a database dump.

Recon & hidden clues

Read from local files

The portal leaves an intentional trail: page comments, a crawler file, a draft security report, and a three-person directory. They point to the missing check, not to a separate exploit.

  1. 1. Login page hintsindex.php HTML commentsLook at robots.txt and sequential account numbers.
  2. 2. Crawler directions/robots.txtNames a hidden report and an employee directory.
  3. 3. Confirm the hypothesis/.security/recon.txtAsks whether profile IDs are checked against the session.
  4. 4. Inspect the referenceprofile.php?id=1The profile URL is the object selector to investigate.
This is the intended discovery trail in the supplied source. No web paths were requested, scanned, or crawled during this review.

HTML source is not PHP source

index.php contains an HTML comment suggesting robots.txt and sequential IDs. profile.php contains an HTML comment suggesting ?id=1, ?id=2, and ?id=3. These comments are deliberately part of the generated page.

In a normal PHP deployment, “View page source” shows returned HTML, not the server-side PHP code. The detailed PHP vulnerability comments are available here because this collection includes the source files; the player-facing HTML hints are a different layer.

robots.txt gives clues, not protection

IDOR/src/robots.txt · complete file
# Welcome, curious visitor!
User-agent: *
Disallow: /admin/
Disallow: /.security/

# Interesting... why would we disallow something that might not exist?
# Have you checked /.security/recon.txt yet?
# Also found: /directory.txt (employee listing)
# Remember: in pentesting, enumeration is key.

Disallow is a crawler instruction, not an authorization rule. It neither authenticates the caller nor makes a file private. The file explicitly advertises the two useful text paths.

The hidden report names the trust boundary

The real hidden file is IDOR/src/.security/recon.txt. It asks whether the URL's profile ID is validated against the session, recommends authorization checks and audit logging, and identifies CWE-639.

.security/recon.txt · lines 15–23
2. ACCESS CONTROL
   - TODO: Verify that profile.php enforces authorization checks
   - REMINDER: Just because a user is authenticated doesn't mean they
     should access ANY resource — they should only access THEIR OWN data

3. OBJECT REFERENCES
   - Profile IDs are passed directly in URL parameters (e.g., ?id=1)
   - Are these direct object references validated against the session?
   - Test: Try changing the id parameter to different values

Its suggestion to use UUIDs is defense in depth, not the fix. An attacker who learns another UUID must still be denied if they lack access.

The directory narrows the lab's search

IDOR/src/directory.txt · relevant facts
Total Employees: 3
Departments: IT, Sales, Administration

The directory does not list usernames, passwords, email addresses, or account IDs. It only supports the idea of a small multi-user system. The initializer independently establishes the fresh seed's three records and insertion order.

The JavaScript console is only a teaching aid

The login page logs hints about IDOR. The profile page's inline JavaScript compares the current requested ID with the session ID and logs a warning when they differ. Those messages do not enforce server-side permissions, and no console was opened here.

A named path is not proof of a live endpoint

/.security/recon.txt and /directory.txt exist in the supplied source tree. An /admin/ directory does not. Docker copies src/ into the web root, but runtime serving rules and reachability were not tested. Do not report a successful request to a path just because robots.txt mentions it.

Keep reconnaissance proportional

In future authorized lab practice, the named hints and the profile URL are enough to form a testable hypothesis. There is no need to scan thousands of IDs or unrelated systems. A controlled comparison between two known accounts is stronger evidence than a long list of guessed references.

Solve walkthrough

Source-derived route

Keep the same login and change only the requested profile. That controlled comparison isolates the authorization failure.

The following explains the intended solve for a freshly initialized, owned training lab. Requests are inert reference text—not commands, captured traffic, or actions performed during this review.

  1. Record the starting identity

    The supplied credential pair is john / password123. The fresh initializer inserts John first, so his account ID is 1. The intended authenticated destination is profile.php?id=1.

    For later practice, confirm the viewer from the “Logged in as” label and use the original session throughout the comparison. Do not edit the session cookie to impersonate another user.

    Illustrative login request · no request sent
    POST /login.php HTTP/1.1
    Host: localhost:8080
    Content-Type: application/x-www-form-urlencoded
    
    username=john&password=password123
  2. Understand the legitimate baseline

    The source-defined baseline displays Account ID 1, username john, email john.doe@company.local, and account type User. John has no flag value.

    Baseline profile request · session value is a placeholder
    GET /profile.php?id=1 HTTP/1.1
    Host: localhost:8080
    Cookie: PHPSESSID=JOHN_SESSION_PLACEHOLDER
    Separate these: the session identifies John; the query parameter identifies the profile object. They happen to match in normal use.
  3. Follow the optional discovery clues

    The HTML comments and robots.txt point to the hidden report and directory. Their useful conclusions are that the system has multiple users and that profile IDs should be checked against the session.

    These clues help a player discover the issue, but they are not prerequisites for the vulnerability. The direct source review already shows that no ownership check runs before the lookup.

  4. Change only the object ID to 2

    Cross-account comparison · same viewer, different object
    GET /profile.php?id=2 HTTP/1.1
    Host: localhost:8080
    Cookie: PHPSESSID=JOHN_SESSION_PLACEHOLDER

    The fresh seed's second record is Jane: username jane, email jane.smith@company.local, role user. The topbar still identifies John because the session has not changed.

    This is the clean horizontal-access example: one ordinary user can read a different ordinary user's profile. The absence of a flag on Jane's row does not mean the authorization test failed.

  5. Request the seeded admin object

    Intended flag request · no admin login required
    GET /profile.php?id=3 HTTP/1.1
    Host: localhost:8080
    Cookie: PHPSESSID=JOHN_SESSION_PLACEHOLDER

    The third record is admin, email admin@company.local, role admin. The record has a flag, and John is not its owner, so the template's flag condition is true.

    The visible “Admin” badge belongs to the displayed object. It does not turn the logged-in John into an administrator.

  6. Connect the result to the missing check

    The profile route checks only isset($_SESSION['user_id']), binds $requestedId into WHERE id = :id, and displays the result. No denial occurs when the requested ID differs from the session ID.

    Finding: an authenticated user can obtain another account's profile fields and the seeded admin flag by manipulating the id query parameter. Root cause: missing object-level authorization in profile.php.
  7. Keep the proof and its limits honest

    A future runtime report should record the authenticated viewer, baseline request, single changed parameter, returned account fields, and absence of authorization denial. Redact live session cookies and sensitive values before sharing it.

    This review has source evidence only. Reading the flag literal in init_db.php is not the same as obtaining it through a running endpoint. There is no screenshot, HTTP transcript, or runtime acceptance claim here.

Reveal the intended target and flag
Source-defined answer · fresh database seed
Viewer: john (user ID 1)
Requested object: /profile.php?id=3
Flag: FLAG{idor_access_control_failure}

Supported by the initializer's third inserted account and the profile template's cross-account flag condition. Not tested against a live service.

If future practice disagrees

SymptomFirst thing to inspect
Redirects back to the login pageThe authentication gate ran. Check whether the intended session is present; an anonymous request is not this solve.
Every request shows John's profileCheck the actual URL. Missing or nonpositive IDs fall back to the session ID.
Jane's profile appears but no flagExpected: only the fresh admin record contains a flag. Jane's disclosure still demonstrates IDOR.
Admin profile appears without the flagCheck whether the viewer is admin (owner condition), the flag is empty, the database differs, or the template was changed.
“No account found” appearsThe ID may not exist, or a database exception may have set the profile to null. This message alone does not prove authorization.
Hidden hint path is unavailablePresence in the source tree does not establish live serving rules. The profile flaw does not depend on fetching the hint.
IDs or credentials differThe initializer skips an existing database. The 1/2/3 mapping applies to the fresh supplied seed, not every deployment.

Things to learn & fix

Authorization, not obscurity

A predictable ID makes discovery easy. The actual vulnerability is accepting a reference without enforcing the caller's permission to access it.

The three ingredients of this IDOR

  • Object: another account's database record.
  • Reference: the client-controlled id parameter.
  • Missing authorization: no owner or policy check before disclosure.

IDs in URLs are not automatically insecure. A numeric key, UUID, filename, slug, or opaque token can all be legitimate references when the server checks access. The same failure can occur in request bodies, hidden form fields, path segments, and API parameters.

Minimal fix for this lab's own-profile policy

The source comments describe a policy where users should only view their own profiles. Enforce it after the existing ID fallback and before the database query. This snippet is documentation only; IDOR/src/profile.php has not been modified.

Proposed insertion after profile.php line 56 · not applied or run
if ($requestedId !== (int)$_SESSION['user_id']) {
    http_response_code(403);
    exit("Forbidden: you do not have access to this profile.");
}

The check uses the trusted session identity, not another client-supplied user_id. It exits before querying or rendering a different account. Validating integer syntax remains useful, but cannot replace this check.

For a “My Profile” route, avoid the selector entirely

If the only permitted object is the viewer's own account, derive its key from the session. There is no need for the browser to select a user at all.

Alternative session-scoped lookup · illustrative, not applied
$viewerId = (int)$_SESSION['user_id'];

$stmt = $db->prepare(
    "SELECT id, username, email, role FROM users WHERE id = :viewer_id"
);
$stmt->execute([':viewer_id' => $viewerId]);
$profile = $stmt->fetch();

This example assumes the existing authentication gate has already passed. It also omits the flag column because a normal own-profile page does not need a secret challenge field.

For broader applications, authorize the action and object

Shared documents, delegated support access, and multi-tenant records need an explicit policy, not universal “viewer ID equals object ID.” Scope queries to permitted owners or tenants, and evaluate any intentional elevated permissions from trusted server-side state.

Do not trust the requested record's role as the viewer's role. Check the caller, the object, and the attempted action—read, update, delete, or export—on every relevant server-side route.

Controls that do not solve this missing check

Existing / suggested controlWhat it helps withWhy IDOR remains
Login and password hashesEstablish identity; protect stored password verification.An authenticated user is still allowed to request someone else's row.
Prepared statementsKeep parameter values separate from SQL syntax.A safe query can still select a record the caller must not read.
Integer castingConverts the supplied reference into a numeric value.Being a number does not establish ownership or permission.
htmlspecialcharsEscapes output for HTML contexts.Safely displaying unauthorized data is still a disclosure.
Hidden links / console warningsGuide normal navigation or provide hints.The client can directly request the endpoint without following its UI.
robots.txt exclusionsTell cooperative crawlers which paths not to crawl.They are not server-side access restrictions.
UUIDs or less predictable IDsMake guessing valid references harder.Known or leaked references must still be denied to unauthorized callers.
Rate limits and audit logsSlow enumeration and improve detection.One unauthorized read remains possible if the permission check is absent.

Regression tests that prove the intended policy

For a later authorized implementation, test successful own-account access and explicit cross-account denial. These are proposed checks, not tests run here.

Viewer / requestRequired result after the minimal fix
No session → any profileAuthentication required; no profile data.
John → ID 1John's permitted fields only.
John → ID 2 or ID 3403 from the documented check; no other user's fields or flag.
Jane → ID 2Jane's permitted fields only.
Jane → ID 1 or ID 3Denied; no cross-account disclosure.
Admin → own ID 3Own profile only; the original owner condition still hides the flag.
John → missing or nonpositive IDPreserves the existing own-profile fallback.
Direct URL / replayed requestThe same policy applies even when navigation links are bypassed.

A production policy may deliberately return a uniform 404 for unauthorized or nonexistent objects to avoid revealing existence. Whatever response is chosen, verify the body contains no forbidden data; status alone is not a complete access-control test.

Keep the intentionally vulnerable lab isolated

Compose uses 8080:80 without a loopback-only host binding, so the documented configuration is not inherently limited to localhost. Do not expose this training portal to untrusted networks. No deployment or port configuration was changed here.

Classification and references

The README and PDF map this exercise to A01:2021 Broken Access Control. MITRE's current CWE-639 entry also lists A01:2025 Broken Access Control. This guide keeps the source's original versioned label rather than silently treating 2021 as the latest edition.

In API discussions, the related broader topic is broken object-level authorization (BOLA). This lab's concrete weakness is authorization bypass through a user-controlled record key; the concepts overlap, but are not interchangeable in every case.

These public references were read on 17 November 2026. They are optional external links; the guide itself makes no network requests.

Self-check

  • Can I distinguish the session's viewer ID from the requested profile ID?
  • Can I show why the integer cast is not an authorization check?
  • Can I explain why a prepared statement does not prevent IDOR?
  • Can I explain why Jane's disclosure proves the flaw without a flag?
  • Can I explain why John viewing admin data is not an admin login?
  • Can I explain why the flag is hidden from its owner but visible to John?
  • Can I identify the exact location for the permission check?
  • Can I name positive and negative cases for a future regression test?

Files & source notes

Provenance & inert excerpts

The PHP source establishes the vulnerability. The seed establishes the intended answer. The README and PDF establish the exercise—not a recorded exploitation transcript.

Reviewed file inventory

Supplied fileRoleReview
IDOR/README.mdScenario, entry credentials, goals, Docker instructions, and hints.Read in full. Build instructions not run.
IDOR/DockerfilePHP 8.2 Apache image, SQLite extension, source copy, writable data path, startup initializer.Read in full. No image built or started.
IDOR/docker-compose.ymlOne service; host port 8080 to container port 80; restart policy.Read in full. No Compose command run.
IDOR/src/index.phpLogin form, existing-session redirect, error labels, HTML and console clues.Read in full as text.
IDOR/src/login.phpPOST authentication, password verification, session assignment, profile redirect.Read in full; not executed.
IDOR/src/profile.phpAuthentication gate, unscoped record lookup, display, cross-account flag condition.Read in full; key lines reproduced as inert text.
IDOR/src/logout.phpClears and destroys the session, then redirects.Read in full; not executed.
IDOR/src/db.phpPDO connection to /var/www/data/app.db.Read in full. No database opened or created.
IDOR/src/init_db.phpFresh-database schema, bcrypt password hashes, three seeded users, flag.Read in full; not executed. No seed data written.
IDOR/src/style.cssOriginal portal's presentation.Read in full. This guide follows the madx/Fly reference styling instead.
IDOR/src/robots.txtCrawler exclusions and explicit clue paths.Read in full; no path requested.
IDOR/src/directory.txtThree-person directory hint.Read in full.
IDOR/src/.security/recon.txtHidden draft report explaining the access-control hypothesis.Read in full, including hidden-directory discovery.
Arshlaan_s Write-ups/IDOR Pentesting Lab.pdfTwo-page exercise handout matching the README's scenario and goals.Native PDF display unavailable; existing extracted text read. No fresh extraction run.

What to retain with the original material

  • Fresh-seed assumption: the initializer inserts John, Jane, and admin in order into a new AUTOINCREMENT table. It skips initialization if app.db already exists. The source-defined ID 1/2/3 mapping is not a claim about a different or previously modified database.
  • Flag provenance: the exact value is in init_db.php. The PDF gives only the FLAG{...} format and the task, not a solved flag or captured response.
  • Authorization versus display: $isOwnProfile detects ownership but is only used to hide the flag from its owner. It never blocks another user's profile.
  • Query scope: password is not selected by the profile query. Avoid reporting passwords or arbitrary database columns as disclosed.
  • Error ambiguity: a missing row and a caught database exception both lead to an empty profile display. “No account found” is not evidence of a permission check.
  • Hint reachability: the hidden text files exist locally; live Apache access was not tested. No src/admin/ directory was found.
  • Database boundary: the intended database is outside the web root. No app.db artifact is supplied in the reviewed IDOR tree.

Source landmarks

  • login.php, lines 24–37: bound username lookup, password verification, session identity, and redirect.
  • profile.php, lines 35–56: session start, authentication gate, integer conversion, and fallback.
  • profile.php, lines 58–68: commented-out ownership check—documentation, not executed enforcement.
  • profile.php, lines 70–81: lookup, exception handling, and ownership calculation.
  • profile.php, lines 127–174: viewer label, selected record's fields, role badge, and conditional flag row.
  • init_db.php, lines 9–15: database path and “already exists” shortcut.
  • init_db.php, lines 28–37 and 52–84: schema, seed order, flag literal, and inserts.
Read the profile's complete server-side request logic · lines 35–82

Original excerpt, including the proposed authorization check as comments. The PHP opening tag below is included to identify the language. Everything is escaped text; nothing is evaluated.

IDOR/src/profile.php · request-handling snapshot
<?php
session_start();
require_once 'db.php';

// -------------------------------------------------------------------
// Gate: require authentication (user must be logged in)
// -------------------------------------------------------------------
if (!isset($_SESSION['user_id'])) {
    header("Location: index.php");
    exit;
}

// -------------------------------------------------------------------
// VULNERABLE CODE: user-controlled "id" parameter is trusted directly
// No authorization check is performed to ensure the logged-in user
// is requesting their own profile.
// -------------------------------------------------------------------
$requestedId = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($requestedId <= 0) {
    // Fall back to the logged-in user's own profile
    $requestedId = $_SESSION['user_id'];
}

// -------------------------------------------------------------------
// MISSING AUTHORIZATION CHECK — this is where the fix would go:
//
//   if ($requestedId !== (int)$_SESSION['user_id']) {
//       http_response_code(403);
//       exit("Forbidden: you do not have access to this profile.");
//   }
//
// Because this check is absent, any valid "id" value will return
// that user's full profile data.
// -------------------------------------------------------------------

try {
    $db   = getDB();
    $stmt = $db->prepare("SELECT id, username, email, role, flag FROM users WHERE id = :id");
    $stmt->execute([':id' => $requestedId]);
    $profile = $stmt->fetch();
} catch (PDOException $e) {
    error_log("Profile error: " . $e->getMessage());
    $profile = null;
}

// Determine if the viewer is looking at someone else's profile
$isOwnProfile = ((int)$_SESSION['user_id'] === $requestedId);
?>
Read the original login.php · complete snapshot
IDOR/src/login.php · original source, not executed
<?php
/**
 * login.php — Authentication Handler
 *
 * Validates credentials and creates a session. On success the user
 * is redirected to their own profile page using their numeric ID.
 */
session_start();
require_once 'db.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header("Location: index.php");
    exit;
}

$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';

if ($username === '' || $password === '') {
    header("Location: index.php?error=1");
    exit;
}

try {
    $db   = getDB();
    $stmt = $db->prepare("SELECT id, username, password FROM users WHERE username = :username");
    $stmt->execute([':username' => $username]);
    $user = $stmt->fetch();

    if ($user && password_verify($password, $user['password'])) {
        // Store only the user's ID and username in the session
        $_SESSION['user_id']   = $user['id'];
        $_SESSION['username']  = $user['username'];

        // Redirect to the profile page using the numeric ID in the URL
        header("Location: profile.php?id=" . $user['id']);
        exit;
    }
} catch (PDOException $e) {
    // In a real app this would be logged, not displayed
    error_log("Login error: " . $e->getMessage());
}

header("Location: index.php?error=1");
exit;
Read the original schema and seed data · includes flag and demo-password spoilers

Exact excerpts from init_db.php, lines 28–37 and 52–75. The passwords below are source-published demo values; the initializer would hash them with bcrypt. It was not run here.

IDOR/src/init_db.php · schema and seed excerpts
$db->exec("
    CREATE TABLE users (
        id       INTEGER PRIMARY KEY AUTOINCREMENT,
        username TEXT    NOT NULL UNIQUE,
        password TEXT    NOT NULL,
        email    TEXT    NOT NULL,
        role     TEXT    NOT NULL DEFAULT 'user',
        flag     TEXT    DEFAULT NULL
    );
");

$users = [
    [
        'username' => 'john',
        'password' => password_hash('password123', PASSWORD_BCRYPT),
        'email'    => 'john.doe@company.local',
        'role'     => 'user',
        'flag'     => NULL
    ],
    [
        'username' => 'jane',
        'password' => password_hash('letmein', PASSWORD_BCRYPT),
        'email'    => 'jane.smith@company.local',
        'role'     => 'user',
        'flag'     => NULL
    ],
    [
        'username' => 'admin',
        'password' => password_hash('admin2024', PASSWORD_BCRYPT),
        'email'    => 'admin@company.local',
        'role'     => 'admin',
        // The flag is hidden here — only reachable through IDOR
        'flag'     => 'FLAG{idor_access_control_failure}'
    ],
];

The original “only reachable through IDOR” comment describes the intended player experience. In a source-inclusive collection, the flag is also readable as a literal; that is why this guide distinguishes static answer knowledge from runtime exploitation.

Read Docker startup and original build instructions · text only

The startup command invokes the database initializer before Apache. It explains the deployment design and was not executed.

IDOR/Dockerfile · line 24
CMD ["bash", "-c", "php /var/www/html/init_db.php && apache2-foreground"]
README build / stop instructions · preserved as inert reference text
cd IDOR
docker compose up --build -d

# Stop the lab later:
docker compose down

These are future-practice instructions only, not actions taken to make this guide. No run buttons, terminal integration, or automatic requests are included.

Review boundaries

  • Checked from local source: request flow, selected fields, missing authorization, viewer-versus-object comparison, fresh-seed order, flag condition, and hidden clue files.
  • Read from documentation: README, the existing PDF text extraction at /tmp/opencode/labs-reference/pdfs/IDOR Pentesting Lab.txt, and the official OWASP/MITRE references linked on the Lessons page.
  • Not performed: executing any local file, PHP linting, database initialization, Docker build/start, browser rendering, test execution, login, enumeration, scanning, or HTTP requests to the lab.
  • Unchanged: all supplied IDOR code, Docker settings, reference HTML files, and the original PDF. Only this standalone guide was added.
  • Not embedded: a database, live session, executable PHP, original PDF, or external assets. Code excerpts are escaped text.
One HTML file, six pages, no external assets or automatic network requests. Copy buttons copy text; page switching, theming, and printing are guide UI only. Print includes all six pages; expand desired spoilers and source excerpts before printing.