openwisp / openwisp/openwisp-controller
[bug] _get_common_name() mutates device name in memory during certificate creation
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 773
- Forks
- 315
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 14
Description
Description
_get_common_name() in AbstractVpnClient (config/base/vpn.py) directly mutates device.name on the live object:
d = self.config.device
d.name = d.name[:end] # mutates live object
This causes:
1. Truncated certificate display name — _auto_x509() calls _get_common_name() first, then passes self.config.device.name to _auto_create_cert(name=...). Since the device name is already truncated in memory, the certificate's name field stores the truncated version instead of the original device name.
2. In-memory state corruption — any code accessing device.name later in the same request (signal handlers, admin display, logging) sees the truncated value instead of the actual device name.
Steps to reproduce
1. Create a device with a name longer than 63 - len(mac_address) characters (e.g. 80 chars)
2. Attach an OpenVPN template with auto_cert=True
3. Save — the certificate's name field will have the truncated device name
4. device.name in memory will also be truncated for the rest of the request
Expected behavior
The certificate should store the full original device name, and device.name should not be mutated in memory.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in config/base/vpn.py at AbstractVpnClient._get_common_name(), then trace the _auto_x509() call to _auto_create_cert(name=...). Verify that common-name shortening does not change self.config.device.name, and confirm that the certificate keeps the original device name while the length constraint remains satisfied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100