Skip to content

Commit 8873405

Browse files
committed
added validation for hostPath
Signed-off-by: Praful Khanduri <holiodin@gmail.com>
1 parent 5e906fe commit 8873405

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pkg/mcp/toolset/toolset.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"path/filepath"
1313
"slices"
14+
"strings"
1415

1516
"github.com/modelcontextprotocol/go-sdk/mcp"
1617
"github.com/pkg/sftp"
@@ -109,6 +110,25 @@ func (ts *ToolSet) TranslateHostPath(hostPath string) (string, error) {
109110
if !filepath.IsAbs(hostPath) {
110111
return "", fmt.Errorf("expected an absolute path, got a relative path: %q", hostPath)
111112
}
112-
// TODO: make sure that hostPath is mounted
113+
if !ts.isMounted(hostPath) {
114+
return "", fmt.Errorf("path %q is not mounted", hostPath)
115+
}
113116
return hostPath, nil
114117
}
118+
119+
func (ts *ToolSet) isMounted(hostPath string) bool {
120+
for _, mount := range ts.inst.Config.Mounts {
121+
location := filepath.Clean(mount.Location)
122+
cleanPath := filepath.Clean(hostPath)
123+
124+
if cleanPath == location {
125+
return true
126+
}
127+
128+
rel, err := filepath.Rel(location, cleanPath)
129+
if err == nil && !strings.HasPrefix(rel, "..") && rel != ".." {
130+
return true
131+
}
132+
}
133+
return false
134+
}

0 commit comments

Comments
 (0)