Skip to content

Commit 7668859

Browse files
committed
fix: use heredoc instead of base64 for remote file writing
BusyBox on minimal OpenWrt builds doesn't include the base64 applet (exit code 127). Switch to cat heredoc with a unique delimiter, which works on any POSIX shell.
1 parent 9336d5c commit 7668859

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

internal/router/provisioner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package router
33
import (
44
"bytes"
55
"context"
6-
"encoding/base64"
76
"fmt"
87
"log"
98
"net"
@@ -225,9 +224,10 @@ func runCommand(client *ssh.Client, cmd string) (string, error) {
225224
}
226225

227226
func writeRemoteFile(client *ssh.Client, path, content string) error {
228-
// Base64-encode content to avoid any shell injection via heredoc delimiters
229-
encoded := base64.StdEncoding.EncodeToString([]byte(content))
230-
cmd := fmt.Sprintf("echo '%s' | base64 -d > %s", encoded, path)
227+
// Use heredoc with a delimiter that won't appear in our controlled content.
228+
// Single-quoted delimiter ('AGENT_EOF') prevents any shell expansion.
229+
const delim = "___COLOMBO_EOF___"
230+
cmd := fmt.Sprintf("cat > %s <<'%s'\n%s\n%s", path, delim, content, delim)
231231
_, err := runCommand(client, cmd)
232232
return err
233233
}

0 commit comments

Comments
 (0)