Skip to content

Latest commit

 

History

History
332 lines (225 loc) · 23 KB

SECURITY.md

File metadata and controls

332 lines (225 loc) · 23 KB

Security Policy

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.


Table of contents

  1. Reporting a vulnerability
  2. Supported versions
  3. Security scope
  4. What python-can is (and is not)
  5. Threat model for integrators
  6. CAN and in-vehicle network security context
  7. Library-specific considerations
  8. Secure deployment patterns
  9. Supply chain and dependencies
  10. Security development practices (maintainers)
  11. References and further reading

Reporting a vulnerability

Please do not file public GitHub issues for undisclosed security vulnerabilities.

Where to report

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>).

What to include

  • 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)

What to expect

  • 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 security in doc/changelog.d/ for fixed issues (see development docs)

Out of scope for library vulnerability reports

  • 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)

Supported versions

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 scope

In scope

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

Out of scope (but still your responsibility)

  • 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

What python-can is (and is not)

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.


Threat model for integrators

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.


CAN and in-vehicle network security context

Defense must be layered (NIST CSF / NHTSA guidance): Identify, Protect, Detect, Respond, Recover.

Protocol reality

  • 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).

Recommended vehicle / plant controls (not provided by python-can)

  1. Segment infotainment, telematics, and diagnostics from safety-critical CAN domains (NHTSA Cybersecurity Best Practices 2022).
  2. Gateway filtering: allow only defined IDs, rates, and modes per operational state (secured gateway requirements).
  3. Rate limiting / ID whitelists at transceiver or ECU level to mitigate flooding (CAN transceiver security, IVNPROTECT).
  4. IDS at network, service, and vehicle-state layers (ITU-T X.1375, SAID (USENIX Sec '22)).
  5. Protect diagnostics: UDS security access, disable unnecessary debug on shipped units (NHTSA §8.1).
  6. Engineering lifecycle: ISO/SAE 21434 and UN R155/R156 for CSMS, TARA, and secure updates.

Library-specific considerations

The following maps this codebase to common security concerns. Paths are relative to the repository root.

1. Privileged bus access

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 / virtual for development and CI (as in .github/workflows/ci.yml with test/open_vcan.sh)
  • Never expose bus-opening containers or VMs to untrusted users

2. Configuration sources

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.

3. Remote and multicast interfaces

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).

4. Native libraries (ctypes)

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

5. Logging, playback, and SQLite

  • Log formats may store full frame payloads—classify files as sensitive; encrypt at rest; restrict ACLs.
  • can/io/sqlite.py interpolates table_name into SQL DDL/DML. Do not pass untrusted table_name from users (SQL injection risk). Use default messages or a strict identifier allowlist.
  • Playback (can.player) on a live bus is equivalent to injection—gate with procedural controls.

6. Message validation

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.

7. Command-line tools

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.

8. Plugin interfaces

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.


Secure deployment patterns

Development and test

  • Prefer interface='virtual' or vcan.
  • 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.

Production / workshop

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)

Robotics / morphle context

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.

Supply chain and dependencies

Runtime dependencies (core)

From pyproject.toml: wrapt, packaging, typing_extensions, msgpack (non-Windows), pywin32 (Windows CPython).

Optional extras

pyserial, python-ics, vendor-specific packages, asammdf, etc. Each expands the attack surface—install only what you need.

Recommended consumer practices

Maintainer / release

  • 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)

Security development practices (maintainers)

  1. Minimize trust boundaries crossed—validate lengths and encodings on network parsers (socketcand receive buffer, multicast unpack).
  2. Parameterized SQL for all user-influenced identifiers in SQLite paths.
  3. Defense in depth for XML/UDP: limit size, reject unexpected tags (already partially done in beacon detection).
  4. Security tests for config loading edge cases (test/test_load_config.py, test/test_util.py).
  5. Enable GitHub Private Vulnerability Reporting and keep this file updated.
  6. Coordinate with upstream hardbyte/python-can for shared code fixes.

References and further reading

Vulnerability reporting and open source hygiene

  1. GitHub: Adding a security policy (SECURITY.md)
  2. Safeguard: How to write a SECURITY.md
  3. GitHub Blog: Maintainer’s guide to vulnerability disclosure
  4. python-can: Development & contributing

Automotive / CAN security

  1. OWASP Automotive Security Cheat Sheet
  2. NHTSA Cybersecurity Best Practices for Modern Vehicles (2022)
  3. NHTSA Cybersecurity Best Practices (2016)
  4. UN Regulation No. 155 (cyber security)
  5. UK VCA: UN R155 & R156 overview
  6. ISO/SAE 21434:2021 — Road vehicles cybersecurity engineering
  7. CiA CCN 2025-09 — Security on CAN (SecOC, CANsec, gaps)
  8. AUTOSAR SWS Secure Onboard Communication (SecOC)
  9. I CAN Hack: Secure Onboard Communication (SecOC)
  10. Secured gateways (Ken Tindell, CiA)
  11. Fraunhofer: CANsec for CAN XL
  12. CAST: CAN / CAN FD / CAN XL safety and security
  13. Evaluation of CAN Bus Security Challenges (PMC)
  14. ITU-T X.1375 — IDS for in-vehicle networks
  15. SAID: State-aware defense against IVN injection (USENIX Sec '22)
  16. Protocol-compliant DoS attacks on CAN (VTC 2016)
  17. Cyber security enhancing CAN transceivers (CiA 2017)
  18. CAN firewall / IDS with secure logging (ACM)

Remote CAN and tooling

  1. socketcand project
  2. CVE-2026-37538 — socketcand buffer overflow advisory
  3. can-hub: python-can remote interfaces (TLS/mTLS)
  4. WOOT '15: Fast and Vulnerable (remote CAN case studies)

Software supply chain

  1. OWASP Software Supply Chain Security Cheat Sheet
  2. OWASP Proactive Controls C6: Secure dependencies
  3. CISA: Securing the software supply chain (developers)
  4. CISA: 2025 SBOM minimum elements
  5. PyPA pip-audit
  6. Snyk: python-can package health

Regulatory / EU product context

  1. CiA: EU Cyber Resilience Act and CAN
  2. EmSA: CANopen (FD) security gap (SOFA / SPsec)

Document history

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).