# VNX-1125: Excessive Attack Surface

Reports Python RPC servers configured to expose far more than their own handlers.

| Field | Value |
|---|---|
| Rule ID | `VNX-1125` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Python |
| CWE | [CWE-1125](https://cwe.mitre.org/data/definitions/1125.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `excessive-attack-surface` `cwe-1125` `rpc` |
| Source | [`internal/sast/rules/vnx-1125.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1125.rego) |

## Overview

VNX-1125 maps to [CWE-1125: Excessive Attack Surface](https://cwe.mitre.org/data/definitions/1125.html). Most attack surface is intended: a web route is an endpoint someone chose to publish. This rule reports the configurations where a Python remote-procedure server publishes **far more than the functions it was written to serve**:

- XML-RPC `register_instance(obj, allow_dotted_names=True)` (or `True` as the second argument): every attribute reachable through dotted names, including module globals, is callable remotely, a documented route to code execution;
- RPyC `ThreadedServer` / `ForkingServer` / `ThreadPoolServer` / `OneShotServer` serving `SlaveService`, `ClassicService` or `MasterService`: the whole Python runtime of the process is remote-callable;
- RPyC protocol settings `allow_all_attrs`, `allow_setattr` or `allow_delattr` set to `True`;
- Pyro4 `config.REQUIRE_EXPOSE = False`: every method of every registered object becomes remote-callable;
- `register_function(eval)`, `exec`, `compile`, `__import__`, `open`, `os.system`, `os.popen` or a `subprocess` function registered as a remote procedure.

Not reported: `register_instance` without dotted names, custom `rpyc.Service` subclasses with `exposed_` methods, Pyro objects marked `@expose`, `register_function` of the application's own handlers, web routes, comments, strings and test files.

## What gets flagged

```python
server.register_instance(Inventory(), allow_dotted_names=True)   # FLAGGED
t = ThreadedServer(SlaveService, hostname="0.0.0.0", port=18812)  # FLAGGED
Pyro4.config.REQUIRE_EXPOSE = False                               # FLAGGED
server.register_function(os.system, "run")                        # FLAGGED
```

```python
class CalcService(rpyc.Service):          # NOT FLAGGED: only exposed_ methods
    def exposed_add(self, a, b):
        return a + b

server.register_instance(Calculator())    # NOT FLAGGED
```

## Remediation

1. Register only the functions clients need, by name, with `register_function`; never pass `allow_dotted_names=True`.
2. Serve a custom `rpyc.Service` that defines `exposed_` methods instead of the classic service, and leave `allow_all_attrs`, `allow_setattr` and `allow_delattr` at their defaults.
3. Keep Pyro's `REQUIRE_EXPOSE` on and mark remote methods with `@Pyro4.expose`.
4. Bind RPC servers to localhost or a private interface and require authentication.

## References

- [CWE-1125: Excessive Attack Surface](https://cwe.mitre.org/data/definitions/1125.html)
- [Python xmlrpc.server: register_instance security warning](https://docs.python.org/3/library/xmlrpc.server.html#xmlrpc.server.SimpleXMLRPCServer.register_instance)
- [RPyC security](https://rpyc.readthedocs.io/en/latest/docs/security.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-1125
// nosec vnx-1125
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1125 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
