Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use random filenames or hashes for blobstorage #4309

Open
link2xt opened this issue Apr 5, 2023 · 7 comments · May be fixed by #4583
Open

Use random filenames or hashes for blobstorage #4309

link2xt opened this issue Apr 5, 2023 · 7 comments · May be fixed by #4583
Assignees
Labels

Comments

@link2xt
Copy link
Collaborator

link2xt commented Apr 5, 2023

Recently there was an accident with a chatbot that replaced its avatar set from the command line with an unrelated avatar of a contact. Both the selfavatar setting and the contact avatar i param pointed to $BLOBDIR/avatar.png at the time it was detected. How this happened is unclear, but it is possible that avatar.png was removed, unmounted or otherwise not detected by the core, and the core stored avatar received from the contact as avatar.png, while selfavatar config still pointed to $BLOBDIR/avatar.png.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should assume that files may be randomly removed. Then there may be dangling $BLOBDIR/... references in the database which may accidentally point to unrelated files, could even be an avatar.png file sent to the bot in private.

To prevent such bugs, we should choose a random filename for the blobdir objects or as a hash of the contents.

Related issue: #3817

@link2xt link2xt added security bug Something is not working labels Apr 5, 2023
@link2xt link2xt removed the bug Something is not working label Apr 18, 2023
@iequidoo iequidoo self-assigned this Apr 29, 2023
@link2xt
Copy link
Collaborator Author

link2xt commented Jul 19, 2023

There is an attempt to fix at #4555, but it does not consider the discussion at #3817, the issue closed in favor of this one.

As a first step I suggest adding Param::Filename in addition to Param::File, to store the original filename. This will be backwards-compatible because if Param::Filename is missing, we can still extract the filename from Param::File which stores the filesystem path to the blob. This Param::Filename should be used as an attachment filename in sent emails so random suffix is not sent over the network.

As a second step we need new APIs to avoid leaking the blob path to the UI, I have drafted them at #3817 (comment)

Once blob paths are not visible in the non-deprecated API anymore and are not sent over the network, we can merge #4555 or even use completely random filenames.

@dumblob
Copy link

dumblob commented Jul 19, 2023

...This Param::Filename should be used as an attachment filename in sent emails so random suffix is not sent over the network.

Will the attachment filename be also encrypted to not leak the file name?

@hpk42
Copy link
Contributor

hpk42 commented Jul 20, 2023 via email

iequidoo added a commit that referenced this issue Jul 25, 2023
#4309)

- Deprecate dc_msg_get_file(). It's kept for compatibility and now creates a temporary directory
  inside the blobdir, saves a file copy with unmangled filename, and returns its path. In the
  housekeeping we regularly clear these directories.
- Add dc_msg_save_file() which saves file copy at the provided path and fails if file already
  exists. The UI should open the file saving dialog, defaulting to Downloads and original filename,
  when asked to save the file. After confirmation it should call dc_msg_save_file().
- Make dc_msg_get_filename() return the original filename for the use as a default in the file
  saving dialog. For this purpose add Param::Filename in addition to Param::File, to store the
  original filename. Param::Filename is used as an attachment filename in sent emails.
- Use random filename suffixes for blobstorage. Thanks to the added Param::Filename these random
  suffixes is not sent over the network.
@link2xt
Copy link
Collaborator Author

link2xt commented Jul 26, 2023

This will also allow us to get rid of the sanitize-filename dependency.

iequidoo added a commit that referenced this issue Jul 26, 2023
…ame (#4309)

It can be used e.g. as a default in the file saving dialog. Also display the original filename in
the message info. For these purposes add Param::Filename in addition to Param::File and use it as an
attachment filename in sent emails.
iequidoo added a commit that referenced this issue Jul 26, 2023
…ame (#4309)

It can be used e.g. as a default in the file saving dialog. Also display the original filename in
the message info. For these purposes add Param::Filename in addition to Param::File and use it as an
attachment filename in sent emails.
iequidoo added a commit that referenced this issue Jul 27, 2023
…ame (#4309)

It can be used e.g. as a default in the file saving dialog. Also display the original filename in
the message info. For these purposes add Param::Filename in addition to Param::File and use it as an
attachment filename in sent emails.
iequidoo added a commit that referenced this issue Jul 27, 2023
…ame (#4309)

It can be used e.g. as a default in the file saving dialog. Also display the original filename in
the message info. For these purposes add Param::Filename in addition to Param::File and use it as an
attachment filename in sent emails.
iequidoo added a commit that referenced this issue Jul 27, 2023
…ame (#4309)

It can be used e.g. as a default in the file saving dialog. Also display the original filename in
the message info. For these purposes add Param::Filename in addition to Param::File and use it as an
attachment filename in sent emails.
iequidoo added a commit that referenced this issue Jul 27, 2023
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Jul 27, 2023
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Jul 27, 2023
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Jul 27, 2023
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Jul 28, 2023
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Jul 30, 2023
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Jul 30, 2023
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Jul 30, 2023
This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.
iequidoo added a commit that referenced this issue Jul 30, 2023
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.
iequidoo added a commit that referenced this issue Jul 30, 2023
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.
iequidoo added a commit that referenced this issue Aug 3, 2023
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Aug 3, 2023
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Jan 24, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
iequidoo added a commit that referenced this issue Mar 8, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Mar 8, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
@iequidoo
Copy link
Collaborator

iequidoo commented Mar 9, 2024

The next steps are:

  • Merge feat: Use random filenames for blobstorage (#4309) #4583, it adds dc_msg_save_file() + random filename suffixes in the blobstorage.
  • Change dc_msg_get_file(), see Mangled attachment/blob filenames  #3817 (comment):

    dc_msg_get_file API should create a temporary directory inside the blobdir, save a copy with unmangled filename, and return its path. In the housekeeping we regularly clear these directories. This API is kept for compatibility, but deprecated.

  • Add some new API like dc_msg_get_filedata_path() that avoids unnecessary copying if an app needs just to open a file.
  • Save files in the blobstorage with completely random filenames.
  • Switch the apps to these new APIs.

We already have dc_msg_get_filename() so UIs can use it for the "Save as" dialog.

EDIT: Currently everything is done in the mentioned PR except "Switch the apps to these new APIs.".

iequidoo added a commit that referenced this issue Mar 11, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Mar 11, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Mar 11, 2024
)

`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Mar 11, 2024
`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Mar 11, 2024
`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Mar 11, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
iequidoo added a commit that referenced this issue Mar 18, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Mar 18, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Mar 18, 2024
`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Mar 18, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
iequidoo added a commit that referenced this issue Apr 24, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Apr 24, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Apr 24, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Apr 24, 2024
`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Apr 24, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
iequidoo added a commit that referenced this issue Apr 24, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue Apr 25, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Apr 25, 2024
`dc_msg_get_file()` should create a temporary directory inside the blobdir, save a copy with
unmangled filename, and return its path. In the housekeeping we regularly clear these
directories. This API is kept for compatibility, but deprecated.

Instead, add `dc_msg_get_filedata_path()` that avoids unnecessary copying if an app needs just to
open a file and its name doesn't matter.
iequidoo added a commit that referenced this issue Apr 25, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
iequidoo added a commit that referenced this issue Apr 26, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue Apr 27, 2024
)

This way filenames in the blobstorage are just random hex numbers. This also allows us to get rid of
the `sanitize-filename` dependency.

This also requires `Param::Filename` to be set to "debug_logging*.xdc" for messages containing
logging webxdc-s, otherwise they are not detected properly. This is done in "fix:
Message::set_file_from_bytes(): Set Param::Filename", so don't forget to update senders as well.
hagenest pushed a commit that referenced this issue Apr 30, 2024
#4309)

... and fails if file already exists. The UI should open the file saving dialog, defaulting to
Downloads and original filename, when asked to save the file. After confirmation it should call
dc_msg_save_file().
iequidoo added a commit that referenced this issue May 21, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue May 21, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
iequidoo added a commit that referenced this issue May 23, 2024
Recently there was an accident with a chatbot that replaced its avatar set from the command line
with an unrelated avatar of a contact. Both the `selfavatar` setting and the contact avatar `i`
param pointed to `$BLOBDIR/avatar.png` at the time it was detected. How this happened is unclear,
but it is possible that `avatar.png` was removed, unmounted or otherwise not detected by the core,
and the core stored avatar received from the contact as `avatar.png`, while `selfavatar` config
still pointed to `$BLOBDIR/avatar.png`.

Such bugs are unavoidable even if the core itself has no bugs as we cannot rely on blobdir not
reside on the faulty network filesystem, being incorrectly backed up and restored etc., so we should
assume that files may be randomly removed. Then there may be dangling `$BLOBDIR/...` references in
the database which may accidentally point to unrelated files, could even be an `avatar.png` file
sent to the bot in private.

To prevent such bugs, we add random filename suffixes for the blobdir objects. Thanks to the added
Param::Filename these random suffixes aren't sent over the network.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants