mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
scp, ssh commands: hide the real fs path on errors
The underlying filesystem errors for permissions and non-existing files can contain the real storage path. Map these errors to more generic ones to avoid to leak this info Fixes #109
This commit is contained in:
@@ -422,8 +422,19 @@ func (c *sshCommand) getDestPath() string {
|
||||
return result
|
||||
}
|
||||
|
||||
// we try to avoid to leak the real filesystem path here
|
||||
func (c *sshCommand) getMappedError(err error) error {
|
||||
if c.connection.fs.IsNotExist(err) {
|
||||
return errors.New("no such file or directory")
|
||||
}
|
||||
if c.connection.fs.IsPermission(err) {
|
||||
return errors.New("permission denied")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *sshCommand) sendErrorResponse(err error) error {
|
||||
errorString := fmt.Sprintf("%v: %v %v\n", c.command, c.getDestPath(), err)
|
||||
errorString := fmt.Sprintf("%v: %v %v\n", c.command, c.getDestPath(), c.getMappedError(err))
|
||||
c.connection.channel.Write([]byte(errorString))
|
||||
c.sendExitStatus(err)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user