> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-graphql-labs/lab-2.md).

# lab-2

## Accidental Exposure of Private GraphQL Fields

**Difficulty:** Practitioner

### Lab Description

The user management functions for this lab are powered by a GraphQL endpoint. The API accidentally exposes user credential fields.

**Objective:** Sign in as the administrator and delete the user `carlos`.

### Solution

**Step 1 — Capture baseline traffic**

Access the lab, navigate to **My account**, and attempt a login with invalid credentials to generate traffic. Capture the requests in Burp Suite.

**Step 2 — Locate the GraphQL endpoint**

In the proxy history, find the `POST /graphql/v1` request that fires after the login attempt. Inspect it — it uses a GraphQL mutation for authentication. The schema details aren't visible from the mutation alone, so introspection is needed to understand the full API surface.

**Step 3 — Run an introspection query**

In Burp, go to **GraphQL > Set Introspection Query** and send it. Copy the returned JSON, then paste it into [GraphQL Visualizer](https://graphql-visualizer.netlify.app/) via **Change Schema → Introspection**. The schema diagram reveals a query named `getUser` that returns a `User` object — and the `User` type includes both `username` and `password` fields.

**Step 4 — Understand the query signature**

The raw introspection JSON shows the full definition of `getUser`:

```json
{
  "name": "getUser",
  "args": [
    {
      "name": "id",
      "type": {
        "kind": "NON_NULL",
        "name": null,
        "ofType": {
          "kind": "SCALAR",
          "name": "Int"
        }
      }
    }
  ],
  "type": {
    "kind": "OBJECT",
    "name": "User"
  }
}
```

This means `getUser` accepts a single non-null integer argument `id` and returns a `User` object.

**Step 5 — Construct a query to extract credentials**

Build a query using this signature:

```graphql
query getUser($id: Int!) {
    getUser(id: $id) {
        username
        password
    }
}
```

With the variable:

```json
{"id": 1}
```

**Step 6 — Retrieve the administrator's credentials**

Send the request. The response returns the administrator's username and plaintext password.

**Step 7 — Log in and delete carlos**

Log in using the administrator credentials. Navigate to the **Admin panel** and delete the user `carlos` to complete the lab.

### Conclusion

The `getUser` query was never intended to be part of the public API surface, but introspection was left enabled, allowing an attacker to discover it. The query exposed the `password` field without any access control checks, turning a schema design oversight into a full credential leak.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-graphql-labs/lab-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
