Skip to content

Conversation

@Crusader99
Copy link
Contributor

@Crusader99 Crusader99 commented Nov 3, 2022

I implemented support for file upload/download in Standard Notes and like to share my solution. Due to time issues some things are currently missing.

TODO:

  • Use sub folders for each user to prevent conflicts
  • Security: Check provided FileId by client is a valid UUID
  • Add v1valet middleware for authentication
  • Integration tests are currently missing and should be added
  • Allow to configure a custom folder path in config

Copy link
Owner

@mdouchement mdouchement left a comment

Choose a reason for hiding this comment

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

I guess all security concerns will come later.

//
files := &files{}
v1restricted.POST("/files/valet-tokens", files.ValetTokens)
// Following endpoints are authorized via valet token
Copy link
Owner

Choose a reason for hiding this comment

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

So we should do something like:

v1valet := v1.Group("")
v1valet.Use(a valet middleware for authentication)
v1valet.POST("/files/upload/create-session", files.CreateUploadSession)

// TODO: Check format of fileId (Security)
// TODO: Allow custom path in config
// TODO: Subfolders for each user (Compatible format with official server)
return "/etc/standardfile/database/" + token.FileId
Copy link
Owner

Choose a reason for hiding this comment

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

Do we have the UserID somewhere to add one more namespace in the path?

Copy link
Contributor Author

@Crusader99 Crusader99 Nov 3, 2022

Choose a reason for hiding this comment

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

The UserID could be derived from token.Authorization.

return nil, errors.New("Invalid path")
}
// TODO: Allow custom path in config
// TODO: Subfolders for each user (Compatible format with official server)
Copy link
Owner

Choose a reason for hiding this comment

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

go1.24 added https://pkg.go.dev/os#Root which helps to improve filesystem security.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants