> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/rest-api/identity-api/identity-api-reference/security-compliance/injection-attack-detection.md). Agents can also search and read this documentation through its [MCP server](https://docs.facephi.com/~gitbook/mcp).

# Injection Attack Detection (IAD)

In the context of facial capture and evaluation, this API enables the detection of:

**Attack vectors:** virtual cameras, external devices, browser attacks, network attacks.

**Attack content:** 3D rendering, facial morphing, face swap, cheap fake, deep fake.

This API requires client-side integration of the IAD capture libraries. The IAD capture library (included in **Selphi**) controls the capture process on the client and generates the **IAD bundle** (an encrypted package of metadata and images).

The API can unpack the client’s IAD bundle to perform both injection attack detection and presentation attack detection.

### Endpoint

```
POST /iad
```

### Headers

| Name            | Type   | Required | Description                                                                                                                                              |
| --------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **x-api-key**   | string | **Yes**  | Authorization API key for access.                                                                                                                        |
| **OperationId** | string | No       | Identifier of the operation in Platform V2. If sent together with `SessionId`, a tracking event is emitted in the Security tab of the operation details. |
| **SessionId**   | string | No       | Session identifier associated with the operation. Required to enable tracking, unless you use `ExtraData`.                                               |
| **ExtraData**   | string | No       | Encrypted token containing `operationId` and `sessionId`. An alternative to sending them separately.                                                     |
| **Family**      | string | No       | Tracking event family. Defaults to `ONBOARDING`.                                                                                                         |

### Request body

**Content-Type:** `application/octet-stream`

#### Parameters

| Parameter    | Type   | Required | Description                                                                                                      |
| ------------ | ------ | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `IAD_BUNDLE` | binary | **Yes**  | Encrypted package of metadata and images. The bundle must be sent as an `application/octet-stream` request body. |

#### Example Request

```bash
curl --location '{IDENTITY_API_BASE_URL}/iad' \
--header 'x-api-key: {API_KEY}' \
--header 'Content-Type: application/octet-stream' \
--data 'IAD_BUNDLE'
```

{% hint style="warning" %}
**Maximum request size: 6 MB.** The binary bundle (`IAD_BUNDLE`), which contains metadata and images, counts toward this limit. If the limit is exceeded, the gateway responds `413` without processing the request. See [Request Size Limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).
{% endhint %}

### Responses

#### `200` Success

#### Response Parameters

| Parameter | Type    | Description                                                                                                               |
| --------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `attack`  | boolean | Boolean value indicating whether an attack was detected. `true`: an attack was detected, `false`: no attack was detected. |

#### Response example

```json
{
  "attack": true
}
```

#### `400` Bad Request

When the request is invalid, the response includes a specific error code in the `errors` field that describes the detected problem. See [IAD error codes](#códigos-de-error-iad).

```json
{
  "status": 400,
  "title": "Bad Request",
  "detail": "Invalid request.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400",
  "errors": [
    "FACE_ANGLE_TOO_LARGE: Facial out-of-plane rotation angle is extremely large"
  ]
}
```

#### IAD error codes

| HTTP Code | Message                                               | Error code             | Description                                                                                                           |
| --------- | ----------------------------------------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------- |
| 400       | Face not found                                        | `FACE_NOT_FOUND`       | No faces were detected in the image.                                                                                  |
| 400       | Face is cropped                                       | `FACE_CROPPED`         | The face is only partially within the image.                                                                          |
| 400       | Face is occluded                                      | `FACE_IS_OCCLUDED`     | The face is partially obscured by an object.                                                                          |
| 400       | Too many faces detected                               | `TOO_MANY_FACES`       | More than one face is visible in the image.                                                                           |
| 400       | Facial out-of-plane rotation angle is extremely large | `FACE_ANGLE_TOO_LARGE` | The angle of the face relative to the camera's viewpoint is too large.                                                |
| 400       | Absolute face size is too small                       | `FACE_TOO_SMALL`       | The face's pixel density is too low; it should be closer to the camera, or the image should have a higher resolution. |
| 400       | Relative face size is too small                       | `FACE_TOO_SMALL`       | The face is too small; it should be closer to the camera so that it occupies a larger portion of the image.           |
| 400       | Face is too close to one or more borders              | `FACE_CLOSE_TO_BORDER` | The face is too close to the edge of the camera's field of view; it should be centered in the camera's view.          |
| 400       | Failed to parse file                                  | `UNKNOWN`              | The file is not a valid encrypted blob payload or is corrupted.                                                       |
| 400       | Failed to read metadata                               | `UNKNOWN`              | The encrypted blob data was not generated in the correct format.                                                      |
| 400       | Failed to decrypt message                             | `UNKNOWN`              | The public-private key pair configured on the server and in the capture library do not match.                         |

#### `401` Unauthorized

```json
{
  "message": "Unauthorized"
}
```

#### `403` Forbidden

```json
{
  "Message": "User is not authorized to access this resource with an explicit deny"
}
```

#### `413` Payload Too Large

The request exceeds the maximum allowed size. The gateway rejects it **without processing it**: the response does not include `serviceResultCode` or `serviceTransactionId`. See [Request size limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).

Request larger than 6 MB and up to 10 MB (`Content-Type: application/json`):

```json
{
  "message": "Request Too Long"
}
```

Request larger than 10 MB (10,485,760 bytes) (`Content-Type: text; charset=utf-8`, plain text, not JSON):

```
HTTP content length exceeded 10485760 bytes.
```

#### `502` Bad Gateway

```json
{
  "status": 502,
  "title": "Bad Gateway",
  "detail": "Server got an invalid response.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502"
}
```

#### `504` Gateway Timeout

```json
{
  "message": "Endpoint request timed out"
}
```

### Integration with Platform V2 (optional)

If the operation is tracked in Platform V2 / IDV Suite, the Endpoint can emit a Tracking event for each IAD call. This integration is **optional** and **additive**: omitting the Tracking headers leaves the Endpoint's behavior identical to that of previous versions.

#### Activation

To enable Tracking for a specific call, simply include the `OperationId` and `SessionId` (or, alternatively, a `ExtraData` Tokenized value containing them). In addition, tracking must be enabled in the tenant's internal configuration; otherwise, the headers are ignored.

#### Published information

When the event is emitted, it appears in the **Security** tab of the operation details with the following fields:

| Field              | Description                                                                                                       |
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
| **IAD Diagnostic** | High-level result: `Attack Not Detected`, `Attack Detected`, or `Error: <detalle>` if detection did not complete. |
| **Request ID**     | Unique request identifier, useful for correlating with logs.                                                      |
| **Version**        | Version of the IAD engine used. Only appears if configured for the tenant.                                        |

The event is emitted for both successful results (`Attack Detected` / `Attack Not Detected`) and errors (engine failure, timeout, invalid bundle), so every IAD invocation is recorded with its high-level result. Internal details of the engine or bundle are not exposed: the event contains only the high-level result and the identifiers required for auditing.

### Client-side integration

To generate the encrypted blob payload, you must use the **Selphi Antispoof Widget** version and capture the `onExtractionFinished`event. The event returns an object containing the facial extraction process results. One of this object's properties is `encryptedLivenessRaw`, which contains the encrypted blob payload.

Once you have the payload, send it to the client's server in a POST request. You can use any HTTP client library, such as Axios or Fetch.

The client's server must receive this payload and send it to the Identity API IAD endpoint. The API returns the results in a JSON object indicating whether the validations pass.

#### Integration example

```javascript
const onExtractionFinished = (extractionResult) => {
  fetch(YOUR_BACKEND_URL, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/octet-stream',
    },
    body: extractionResult.detail.encryptedLivenessRaw
  }).then(response => {
    return response.json();
  }).then(result => {
    console.log('RESULT FROM SERVICE', result);
  }).catch(e => {
    console.error(e);
  });
}
```
