Repository navigation
hardening: contain device backup file paths within the configured directories - #216
Merged
Merged
Conversation
…ories
The per-device backup file and folder are named from device-controlled
values: the device 'directory' field, the device hostname, and a name
parsed from the returned configuration. plugin_routerconfigs_download_config()
now routes these through two helpers before building the read, write, and
removal paths:
- plugin_routerconfigs_safe_name() requires a single filename component
(no separators, NUL, or parent references), used for the hostname and
the parsed name;
- plugin_routerconfigs_safe_subdir() keeps the 'directory' field relative
to the backup and archive roots, rejecting any '..' component.
A device whose fields fail these checks has its backup skipped with a logged
error instead of acting on a path outside the configured roots.
Adds tests/Security/BackupPathContainmentTest.php covering both helpers.
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
strpbrk() already rejects '/', '\\', and NUL on every platform, so by the time control reaches the basename() comparison it can never differ from the input. The branch was unreachable, leaving its line uncovered. Removing it keeps the single-component guarantee and restores full changed-line coverage. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
xmacan
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
plugin_routerconfigs_download_config()builds the backup file and folder from device-controlled values — the device Directory field, the device Hostname, and a name parsed from the returned configuration — and used them directly when reading, writing, and removing the backup file.This change routes those values through two new helpers before any path is built:
plugin_routerconfigs_safe_name($name)— requires a single filename component (no/,\, NUL, or./..), applied to the hostname and the parsed configuration name.plugin_routerconfigs_safe_subdir($dir)— keeps the per-device Directory field relative to the configured backup and archive roots, normalising separators, dropping leading slashes, and rejecting any..component.A device whose fields fail these checks has its backup skipped with a logged error, instead of acting on a path outside the configured backup/archive directories.
Tests
tests/Security/BackupPathContainmentTest.phpcovers both helpers (accepted and rejected inputs). Reverting the helpers to their prior behaviour fails the new test; the full plugin suite passes (358 tests, 1897 assertions).Fixes #215