AI Ethics and Governance Intermediate 13 minutes

Security and Robustness

Adversarial examples, data poisoning, backdoors and prompt injection.

Your progress in the track0%

A taxonomy of attacks

StageAttackGoal
TrainingPoisoning, backdoorsChanging the model's behaviour
InferenceAdversarial examplesFooling the decision
InferenceModel extractionCopying the model through queries
InferenceMembership inferenceViolating privacy
Language modelsDirect and indirect injectionBypassing instructions and leaking data

Example: FGSM

$$x_{adv} = x + \epsilon \cdot \mathrm{sign}\big(\nabla_x \mathcal{L}(f(x), y)\big)$$

import torch
def fgsm(model, x, y, eps=2/255):
    x = x.clone().requires_grad_(True)
    loss = torch.nn.functional.cross_entropy(model(x), y)
    loss.backward()
    return (x + eps * x.grad.sign()).clamp(0, 1).detach()

Prompt injection

  • Direct: the user writes “Ignore the previous instructions…”.
  • Indirect: instructions hidden in a web page or document that the agent reads.
  • Defences: separating instructions from data as far as possible, restricting tool permissions, human confirmation of sensitive actions, and monitoring outputs. No complete solution is known so far.

Natural robustness

A change in lighting, device or dialect is not an attack, but it reveals a similar fragility. Evaluate the model on out-of-distribution data.

Defensive practices

  • Verifying data sources and the supply chain, including pretrained models.
  • Red teaming before and after deployment.
  • The principle of least privilege.
  • An incident response plan.

Lesson terms

Red teaming
An organized attempt to discover a system's weaknesses by simulating the behaviour of attackers or misuse.
Adversarial example
An input altered by a small change, often imperceptible to humans, that makes the model err confidently.
Data poisoning
Inserting malicious examples into the training data to influence the model's behaviour.

Abstract

AI systems are vulnerable to specific attacks. Adversarial examples are small changes to the inputs that fool the model. Data poisoning plants malicious examples in the training data, and backdoors make the model behave in a specific way when a certain pattern appears. In language models, prompt injection changes the system's behaviour through text in the inputs or the retrieved content. Robustness also includes performance under natural changes in the data. Defences include adversarial training, verifying data sources, restricting permissions, and red teaming.

Review questions

  1. What is the idea of the FGSM attack?

    Moving the input a small step in the direction of the sign of the loss gradient with respect to the input, to increase the loss.

  2. Why is indirect prompt injection dangerous for agents?

    Because the agent reads external content that may contain malicious instructions, and then carries out actions with its permissions.

Sources and references

  1. Goodfellow, Shlens & Szegedy (2014) — Explaining and Harnessing Adversarial Examples
  2. NIST AI 100-2 — Adversarial Machine Learning: A Taxonomy and Terminology
  3. MITRE ATLAS
  4. OWASP — Top 10 for LLM Applications

Complete the lesson