Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mount-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ describe("exact local-layout contract", () => {
pathArgs: " --remote-path '/github/../secrets'",
message: /relayfile remote root contains a traversal segment/,
},
{
pathArgs: " --remote-path 'github/repos/acme/cloud'",
message: /relayfile remote root must be absolute/,
},
{
pathArgs: " --remote-path '/'",
message: /relayfile remote root must not be empty/,
},
]) {
let shell = template.startShellTemplate;
for (const [key, value] of Object.entries(values)) {
Expand Down
2 changes: 2 additions & 0 deletions src/mount-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,11 @@ function dynamicMountPreflight(pathArgsPlaceholderArg: string): string[] {
'while [ "$#" -gt 0 ]; do',
'if [ "$#" -lt 2 ] || [ "$1" != "--remote-path" ]; then echo "invalid relayfile mount path args" >&2; exit 2; fi;',
'relayfile_mount_remote_path="$2";',
'case "$relayfile_mount_remote_path" in /*) ;; *) echo "relayfile remote root must be absolute" >&2; exit 2 ;; esac;',
'case "/${relayfile_mount_remote_path#/}/" in */../*|*/./*) echo "relayfile remote root contains a traversal segment" >&2; exit 2 ;; esac;',
'relayfile_mount_remote_suffix="${relayfile_mount_remote_path#/}";',
'relayfile_mount_remote_suffix="${relayfile_mount_remote_suffix%/}";',
'if [ -z "$relayfile_mount_remote_suffix" ]; then echo "relayfile remote root must not be empty" >&2; exit 2; fi;',
Comment on lines 790 to +792

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject every all-slash remote root

When a late-bound argument is --remote-path '//' (or contains more slashes), ${var#/} and ${var%/} each remove only one slash, so the suffix remains nonempty and this check permits the root-equivalent path. The template then starts a daemon against the local mount root instead of visibly rejecting the root-empty argument; strip all leading/trailing slashes or explicitly reject an all-slash value.

Useful? React with 👍 / 👎.

'case "$relayfile_mount_preflight_root" in',
'"$relayfile_mount_remote_suffix") relayfile_mount_preflight_root=/ ;;',
'*/"$relayfile_mount_remote_suffix") relayfile_mount_preflight_root="${relayfile_mount_preflight_root%"/$relayfile_mount_remote_suffix"}"; [ -n "$relayfile_mount_preflight_root" ] || relayfile_mount_preflight_root=/ ;;',
Expand Down
Loading