Skip to content

[Security review][L7] Reject reserved device names with trailing spaces/dots - #35

Merged
gistrec merged 2 commits into
masterfrom
fix/reserved-device-trailing-chars
Jul 6, 2026
Merged

[Security review][L7] Reject reserved device names with trailing spaces/dots#35
gistrec merged 2 commits into
masterfrom
fix/reserved-device-trailing-chars

Conversation

@gistrec

@gistrec gistrec commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Problem

isReservedDeviceName (src/Protocol.hpp) compares the name stem byte-for-byte against CON/PRN/AUX/NUL/COM1-9/LPT1-9. Windows, however, strips trailing spaces and dots from a filename component before resolving it to a device.

The stem is taken as everything before the first ., so trailing dots are already dropped when the extension is split off — but a trailing space in the base name survives the split, so con , com1 and the com1 base of com1 .txt sail through sanitizeName unchanged even though the OS still opens them as devices.

Impact is limited (only receive without an explicit -f, and bytes land in <name>.part first), but the filter should match Windows' actual matching rules.

Fix

Trim trailing spaces from the stem before the comparison. Dots need no trimming here — the stem is name.substr(0, name.find('.')), so it can never contain one.

Tests

Extended Protocol.SanitizeNameRejectsDangerous with the trailing-space cases con , aux , and com1 .txt, plus a negative console.log asserting a base that merely starts with a device prefix is not over-blocked. Full suite passes.

Windows strips trailing spaces and dots before matching device names, so
"con ", "nul.", "com1 .txt" resolved to devices while slipping past the
byte-for-byte stem comparison in isReservedDeviceName. Trim trailing ' '
and '.' from the stem before comparing.
@gistrec gistrec added bug Something isn't working security Security-related fix or vulnerability labels Jul 6, 2026
@gistrec gistrec changed the title Reject reserved device names with trailing spaces/dots [Security review][L7] Reject reserved device names with trailing spaces/dots Jul 6, 2026
The stem is name.substr(0, name.find('.')), so it never contains a dot:
the extension is already dropped. The '.' in find_last_not_of(" .") was
therefore dead, and the "nul." test passed via that substr, not the new
trim. Drop '.' from the set, rewrite the misleading comment, replace the
redundant "nul." case with "aux " (exercises the space path on another
device branch), and add a negative "console.log" case asserting a base
that merely starts with a device prefix is not over-blocked.
@gistrec
gistrec merged commit d93f876 into master Jul 6, 2026
6 checks passed
@gistrec
gistrec deleted the fix/reserved-device-trailing-chars branch July 6, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security-related fix or vulnerability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant