> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/sdk-lite/setup/ios/security-checks.md).

# Security Checks

## Context

Face Liveness Lite protects the liveness result with two independent layers of checks:

| Layer                                         | Where it runs                                           | Can the app turn it off?   | How it reaches your app                                                                |
| --------------------------------------------- | ------------------------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------- |
| [Certta device checks](#certta-device-checks) | On the device, before and during the capture            | Yes, with `enableSecurity` | `didFinishWithError(type: .securityException, description:)`, with no `signedResponse` |
| [Liveness checks](#liveness-checks)           | On the liveness servers, while the capture is processed | No                         | `didFinishWithFailure(type:description:signedResponse:)`, with a `signedResponse`      |

Both layers are part of every capture. The Certta device checks can be turned off with `enableSecurity`. The liveness checks cannot be turned off from the app.

## Certta Device Checks

The SDK checks the device and the app environment to make sure the result was not tampered with. If the environment looks compromised, the SDK stops and returns an error instead of a result.

### What is checked

| Area                        | Examples                                                   |
| --------------------------- | ---------------------------------------------------------- |
| Device integrity            | A jailbroken device                                        |
| Instrumentation and hooking | Tools that inject code into the app or intercept its calls |
| Debugging                   | Debugging tools attached to the app                        |
| App and SDK integrity       | A modified or re-signed app binary, or a patched SDK       |

Any finding blocks the capture. There is no severity level that is allowed to continue.

{% hint style="info" %}
The capture only runs on a physical device. The iOS Simulator is not supported.
{% endhint %}

### How it works

{% stepper %}
{% step %}

## Before the capture

When you call `startSDK(viewController:)`, the SDK checks the camera permission and then runs the device checks, before it creates the liveness session and opens the camera. If a threat is found, the camera never opens.
{% endstep %}

{% step %}

## During the capture

While the capture is running, the SDK checks the device again periodically. If a threat appears, for example a hooking tool attached in the middle of the capture, the capture is stopped right away.
{% endstep %}

{% step %}

## At the end

When the run ends, with any outcome, the monitoring stops.
{% endstep %}
{% endstepper %}

`prewarm()` does not run the device checks. They always run when `startSDK` is called, whether or not the session was prewarmed.

The result is not saved on the device. Every `startSDK` call runs the checks again, so the same environment returns the same result until the condition that triggered it goes away.

### Configuration

`enableSecurity` is set in the constructor and defaults to `true`:

```swift
let sdk = CafFaceLivenessLiteSDK(enableSecurity: true)
```

| Scenario                               | `enableSecurity`     | Effect                                                                 |
| -------------------------------------- | -------------------- | ---------------------------------------------------------------------- |
| Production                             | `true` (recommended) | The device checks run and `securityException` can be returned          |
| Manual QA and acceptance testing       | `true` (recommended) | Same behavior as production, so tests reflect what users get           |
| Automated UI tests                     | `false`              | The device checks do not run, so test tooling cannot interrupt the run |
| Any build with `enableSecurity: false` | `false`              | `securityException` is never returned                                  |

The `environment` passed to `setup` (`.dev`, `.beta` or `.prod`) does not change the device checks. Only `enableSecurity` does.

{% hint style="warning" %}
Keep `enableSecurity` set to `true` in production. Turning it off removes the protection against compromised devices.
{% endhint %}

### When a threat is found

The SDK calls `didFinishWithError(type: .securityException, description:)`. No capture is assessed and no `signedResponse` is returned.

The `description` is technical text meant for your logs. Do not parse it or show it to the user. If you need help with a case, share it with Certta support as-is.

Retrying in the same environment returns the same error until the condition that triggered it goes away. For the recommended message and what to do, see [`securityException`](https://docs.caf.io/sdk-lite/error-handling/ios/error-handling.md#securityexception).

## Liveness Checks

The capture is processed by the liveness service, which runs its own checks against presentation attacks, such as photos, screens or masks, and against digital injection attacks, such as manipulated video streams or a tampered app. These checks run on the server, so they cannot be bypassed on the device.

When these checks do not pass, the capture is still processed and the SDK calls `didFinishWithFailure(type:description:signedResponse:)` with a `signedResponse`. Validate it on your backend like any other result.

{% hint style="warning" %}
Never decide the liveness outcome on the client. Your backend validates the `signedResponse` and then retrieves the final result with the `livenessAttemptId` it carries. See [Backend Setup](https://docs.caf.io/sdk-lite/setup/backend/setup.md).
{% endhint %}

### Feedback codes

When a capture does not pass, the SDK delivers the most likely reason as the `type` of `didFinishWithFailure`, a `CafFailureType` value. A code the SDK does not recognize is returned as `unknown`. The full list is in [Result Reference](https://docs.caf.io/sdk-lite/setup/ios/result-reference.md).

Feedback codes are guidance for the next attempt, not a description of what was detected. Device-related feedback is deliberately general: describing which signals are assessed would help attackers adapt.

For the recommended message for each type, including `motionIssue` and `deviceIssue`, see [Failure Reasons and User Guidance](https://docs.caf.io/sdk-lite/failure-handling/mobile/failure-handling.md).

### Errors during the capture

When the capture cannot be completed, the SDK calls `didFinishWithError(type:description:)`. See [Error Handling](https://docs.caf.io/sdk-lite/error-handling/ios/error-handling.md) for what each type means and what to do.

### Liveness environments

The liveness checks run in the environment configured for your account. That environment is set up by Certta. If you need a different setup for testing, contact your Certta account team.

## Testing Your Integration

* Test on a physical device. The iOS Simulator cannot run the capture.
* Keep `enableSecurity = true` in manual QA. Set it to `false` only for automated UI tests.
* The liveness checks run on every capture, whatever the build type or the value of `enableSecurity`.
* To reproduce what your users get, test with a build distributed the same way as production, such as TestFlight or the App Store.
* If test captures keep returning `deviceIssue`, send the `signedResponse` of each attempt, with the date and time, to your Certta account team.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.caf.io/sdk-lite/setup/ios/security-checks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
