This document describes how to report security issues in python-can, what is in scope, and how to use the library safely in environments where CAN bus access can affect safety, privacy, or operations (vehicles, industrial control, robotics, medical devices, etc.).
It is informed by review of this repository, CAN/automotive security literature, and common secure-software practices. It is guidance, not a certification or warranty.
- Reporting a vulnerability
- Supported versions
- Security scope
- What python-can is (and is not)
- Threat model for integrators
- CAN and in-vehicle network security context
- Library-specific considerations
- Secure deployment patterns
- Supply chain and dependencies
- Security development practices (maintainers)
- References and further reading
Please do not file public GitHub issues for undisclosed security vulnerabilities.
| Channel | Use when |
|---|---|
| GitHub Private Vulnerability Reporting (PVR) | Preferred if enabled on this repository’s Security tab |
| Upstream hardbyte/python-can PVR / maintainers | Issues in the core can package that also affect upstream |
| This fork’s maintainers | Issues specific to this fork (morphiens/pythoncan) or deployment context |
If no private channel is available, contact repository maintainers directly with a clear subject line (e.g. python-can security: <short title>).
- Affected version (e.g.
can.__version__or PyPI release) - Platform (OS, Python implementation, backend interface:
socketcan,pcan,socketcand, etc.) - Steps to reproduce (minimal script or CLI invocation)
- Impact (confidentiality / integrity / availability / safety relevance)
- Proof of concept if available (keep it responsible—no live vehicle tests without authorization)
- Acknowledgement within a reasonable timeframe (target: 10 business days; adjust per maintainer capacity)
- Triage and severity assessment
- Coordinated disclosure: agree on a publication date before public disclosure
- Credit to reporters who wish to be named (unless they prefer anonymity)
- A towncrier fragment with category
securityindoc/changelog.d/for fixed issues (see development docs)
- Attacks that require physical OBD/CAN access you already authorized on a production vehicle (report to the vehicle OEM/program owner)
- Vulnerabilities in third-party hardware drivers,
socketcand, Vector/Kvaser SDKs, or optional extras (python-can-remote, etc.)—report to those projects - Missing SecOC / CANsec in Classical CAN (by design at the protocol layer; see below)
| Version line | Security support |
|---|---|
| 4.x (current in this tree) | Security fixes for confirmed vulnerabilities in supported backends and core APIs |
| 3.x | Best-effort only; upgrade to 4.x recommended |
| 2.x and older | Not supported |
Install from PyPI or a verified vendor package. Pin versions in production and verify checksums where your process requires it.
Security defects in the python-can Python package when used as documented:
- Core APIs:
can.Bus,can.Message,can.Notifier, loggers/players, configuration loading - Built-in interfaces under
can/interfaces/(e.g.socketcan,virtual,socketcand,udp_multicast,slcan, vendor ctypes bindings) - CLI entry points:
can_logger,can_player,can_viewer,can_logconvert - Unsafe handling of untrusted files, network peers, or environment configuration that leads to code execution, unintended bus transmission, or exploitable crashes in python-can itself
- Security of the CAN bus, ECUs, gateways, or OEM networks
- Misuse of APIs to send unauthorized frames to a live vehicle or plant
- Compromise of the host OS, Python runtime, or hardware adapters outside this library
- Third-party plugin interfaces listed in the documentation as externally maintained
python-can is a user-space library that abstracts CAN hardware and provides logging, playback, and tooling. It runs with the privileges of the calling process—often including direct access to kernel CAN devices (socketcan), vendor DLLs, or remote CAN bridges.
It does not:
- Authenticate CAN frames on the bus (Classical CAN / CAN FD have no native sender authentication in ISO 11898-1)
- Enforce OEM security gateways, SecOC, or IDS rules
- Replace safety processes, homologation, or UN R155 / ISO 21434 programs
Any process that can open a bus can typically read and inject traffic permitted by the OS and adapter.
When embedding python-can in a product or toolchain, assume:
| Threat | Relevance |
|---|---|
| Bus injection / spoofing | Any holder of a connected interface can send arbitrary IDs (unless lower layers enforce policy) |
| Replay | Recorded logs (ASC, BLF, SQLite, etc.) can be replayed unless higher layers use freshness (e.g. SecOC) |
| Denial of service | High-rate transmission can flood the bus (protocol-compliant DoS is a known CAN weakness) |
| Remote CAN bridging | socketcand, UDP multicast, serial SLCAN, and remote plugins extend the attack surface to the network |
| Privilege escalation via native code | Many backends load vendor shared libraries through ctypes (can/ctypesutil.py) |
| Sensitive data in logs | Trace files may contain VIN-related, location, calibration, or cryptographic material from the bus |
| Supply chain | Transitive Python and native dependencies must be tracked (OWASP/CISA SBOM guidance) |
UN Regulation R155 explicitly lists threats such as CAN flooding, malicious internal messages, and OBD/diagnostic abuse—python-can is a capable tool in authorized test beds and a risk multiplier if deployed with excessive privileges on production paths.
Defense must be layered (NIST CSF / NHTSA guidance): Identify, Protect, Detect, Respond, Recover.
- ISO 11898-1 (Classical CAN, CAN FD, CAN XL data link) does not provide cybersecurity controls; security is added at higher layers or via extensions (CiA CCN 2025-09).
- AUTOSAR SecOC adds MAC and freshness for configured PDUs (AUTOSAR SWS SecOC, practical overview). It does not stop a compromised legitimate ECU from sending valid authenticated traffic (OWASP Automotive Security).
- CANsec (CAN XL link-layer security) addresses authentication, integrity, optional encryption, and replay at a lower layer (Fraunhofer CANsec, CAST white paper).
- CANopen (FD) security (SOFA, SPsec) and secured gateways are complementary (CiA proceedings).
- Segment infotainment, telematics, and diagnostics from safety-critical CAN domains (NHTSA Cybersecurity Best Practices 2022).
- Gateway filtering: allow only defined IDs, rates, and modes per operational state (secured gateway requirements).
- Rate limiting / ID whitelists at transceiver or ECU level to mitigate flooding (CAN transceiver security, IVNPROTECT).
- IDS at network, service, and vehicle-state layers (ITU-T X.1375, SAID (USENIX Sec '22)).
- Protect diagnostics: UDS security access, disable unnecessary debug on shipped units (NHTSA §8.1).
- Engineering lifecycle: ISO/SAE 21434 and UN R155/R156 for CSMS, TARA, and secure updates.
The following maps this codebase to common security concerns. Paths are relative to the repository root.
Opening can.Bus(...) attaches to a real controller when configured to do so. Scripts and services should:
- Run under dedicated least-privilege accounts
- Use
vcan0/virtualfor development and CI (as in.github/workflows/ci.ymlwithtest/open_vcan.sh) - Never expose bus-opening containers or VMs to untrusted users
can.util.load_config() merges configuration from, in order: explicit dict → can.rc → environment → files including /etc/can.conf, ~/.can, ~/.canrc, and CAN_CONFIG JSON (can/util.py).
| Source | Risk | Mitigation |
|---|---|---|
CAN_CONFIG / CAN_CONFIG_* env JSON |
json.loads on operator-controlled env |
Restrict env on shared systems; avoid world-writable service units |
| World-readable config files | Bus channel/interface hijacking | File permissions 0640 or tighter; validate in orchestration |
CLI extra_args → cast_from_string |
Typed kwargs passed to Bus() |
Do not pass untrusted strings into can_logger / automation |
cast_from_string only coerces numbers and booleans; it does not execute code—but downstream interfaces may interpret string kwargs dangerously if a backend is buggy.
| Interface | Notes |
|---|---|
socketcand (can/interfaces/socketcand/socketcand.py) |
Plain TCP ASCII protocol; no TLS or auth in the protocol. UDP beacon XML is parsed with xml.etree.ElementTree. Treat socketcand hosts as OT-critical: firewall port 29536 (default), VPN-only, no Internet exposure. Known native flaws in socketcand itself (e.g. CVE-2026-37538) affect the daemon, not python-can, but the combined system is at risk. |
udp_multicast (can/interfaces/udp_multicast/bus.py) |
Default multicast groups; no encryption or authentication; unreliable ordering. Any host on the LAN segment can inject frames. Scope multicast with TTL/hop limit and network segmentation. |
python-can-remote (optional extra) |
Use only with documented TLS/mTLS where supported (can-hub). |
Vendor backends (PCAN, Kvaser, Vector, IXXAT, etc.) load proprietary .so / .dll via can/ctypesutil.py. Risks:
- DLL search path hijacking on Windows
- Memory safety bugs in vendor code becoming RCE in your process
- Mitigate: install drivers from official sources, verify hashes, run with minimal privileges, keep firmware/drivers patched
- Log formats may store full frame payloads—classify files as sensitive; encrypt at rest; restrict ACLs.
can/io/sqlite.pyinterpolatestable_nameinto SQL DDL/DML. Do not pass untrustedtable_namefrom users (SQL injection risk). Use defaultmessagesor a strict identifier allowlist.- Playback (
can.player) on a live bus is equivalent to injection—gate with procedural controls.
can.Message(..., check=False) by default does not validate DLC vs data length (can/message.py). Invalid frames may be accepted and forwarded to hardware. For fuzzing harnesses, enable check=True; for production send paths, validate IDs and payloads against your application allowlist.
can_logger, can_viewer, and related tools inherit interface selection from config files and argv. Wrap them in systemd/docker with read-only bus where the backend supports it (e.g. can-hub ACLs), or use logger-only workflows.
Backends loaded via entry points (can._entry_points) may execute third-party code at import time. Only install plugins from trusted publishers; audit optional extras in pyproject.toml.
- Prefer
interface='virtual'orvcan. - Record traces for replay offline; do not point players at hardware unless intended.
- Add CAN filters (
can_filters) to reduce attack surface and accidental exposure of unrelated IDs.
| Practice | Rationale |
|---|---|
| Isolate CAN tooling VLAN / bench network | OWASP automotive segmentation |
| No remote socketcand without VPN + ACL | Unauthenticated remote bus (socketcand risk) |
| TLS for any CAN-over-IP gateway | OWASP external connection guidance |
| Separate capture (read) from calibration (write) roles | Authorization per operation |
| Monitor for anomalous ID rates | UN R155 threat 24.1 (flooding) |
| Retain logs without secrets; integrity-protect audit trails | Research on secure CAN logging (ACM IDS/S-LOG) |
If this fork is used on robot or manufacturing lines:
- Treat CAN like machine I/O: interlocks, E-stop, and safety PLCs must not rely solely on bus secrecy.
- Python tooling should not run on safety-rated controllers; use it on supervisory nodes with read-only taps where possible.
From pyproject.toml: wrapt, packaging, typing_extensions, msgpack (non-Windows), pywin32 (Windows CPython).
pyserial, python-ics, vendor-specific packages, asammdf, etc. Each expands the attack surface—install only what you need.
- Generate and monitor an SBOM per release (CISA SBOM minimum elements, consumption guide)
- Run
pip-auditor equivalent on locked environments (PyPA pip-audit) - Pin versions; use hash-checking or
uv sync --lockedwhere applicable (OWASP dependency management, pip secure installs) - Follow OWASP Software Supply Chain Security for CI/CD and dependency updates (OWASP Proactive Control C6)
- CI runs tox, mypy, ruff, pylint, black across platforms (see
.github/workflows/ci.yml) - Releases use GitHub Actions to publish to PyPI (development docs)
- Document security fixes via
doc/changelog.d/<id>.security.md(towncrier)
- Minimize trust boundaries crossed—validate lengths and encodings on network parsers (
socketcandreceive buffer, multicast unpack). - Parameterized SQL for all user-influenced identifiers in SQLite paths.
- Defense in depth for XML/UDP: limit size, reject unexpected tags (already partially done in beacon detection).
- Security tests for config loading edge cases (
test/test_load_config.py,test/test_util.py). - Enable GitHub Private Vulnerability Reporting and keep this file updated.
- Coordinate with upstream hardbyte/python-can for shared code fixes.
- GitHub: Adding a security policy (SECURITY.md)
- Safeguard: How to write a SECURITY.md
- GitHub Blog: Maintainer’s guide to vulnerability disclosure
- python-can: Development & contributing
- OWASP Automotive Security Cheat Sheet
- NHTSA Cybersecurity Best Practices for Modern Vehicles (2022)
- NHTSA Cybersecurity Best Practices (2016)
- UN Regulation No. 155 (cyber security)
- UK VCA: UN R155 & R156 overview
- ISO/SAE 21434:2021 — Road vehicles cybersecurity engineering
- CiA CCN 2025-09 — Security on CAN (SecOC, CANsec, gaps)
- AUTOSAR SWS Secure Onboard Communication (SecOC)
- I CAN Hack: Secure Onboard Communication (SecOC)
- Secured gateways (Ken Tindell, CiA)
- Fraunhofer: CANsec for CAN XL
- CAST: CAN / CAN FD / CAN XL safety and security
- Evaluation of CAN Bus Security Challenges (PMC)
- ITU-T X.1375 — IDS for in-vehicle networks
- SAID: State-aware defense against IVN injection (USENIX Sec '22)
- Protocol-compliant DoS attacks on CAN (VTC 2016)
- Cyber security enhancing CAN transceivers (CiA 2017)
- CAN firewall / IDS with secure logging (ACM)
- socketcand project
- CVE-2026-37538 — socketcand buffer overflow advisory
- can-hub: python-can remote interfaces (TLS/mTLS)
- WOOT '15: Fast and Vulnerable (remote CAN case studies)
- OWASP Software Supply Chain Security Cheat Sheet
- OWASP Proactive Controls C6: Secure dependencies
- CISA: Securing the software supply chain (developers)
- CISA: 2025 SBOM minimum elements
- PyPA pip-audit
- Snyk: python-can package health
| Date | Change |
|---|---|
| 2026-11-12 | Initial comprehensive SECURITY.md for this repository (fork of hardbyte/python-can) |
This file was created to address the absence of a published security policy noted in community assessments (e.g. Linux Foundation OpenSSF insights).