Skip to content

fix(files): Prevent corruption of files when moving from encrypted to unencrypted folders within the same object storage - #62364

Merged
DerDreschner merged 1 commit into
masterfrom
fix/prevent-s3-corruption
Aug 7, 2026
Merged

fix(files): Prevent corruption of files when moving from encrypted to unencrypted folders within the same object storage#62364
DerDreschner merged 1 commit into
masterfrom
fix/prevent-s3-corruption

Conversation

@DerDreschner

@DerDreschner DerDreschner commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

When using server-side encryption (SSE), not all folders are encrypted by default. For example, when using groupfolders, the encryption must be enabled separately. This is described in the admin manual, but might not always being recognized by the administrators. This can then lead to situations where the personal folders are encrypted, but group folders might not.

This will lead to a bug when both folders are inside the same object storage (since #47986). In this case, the current code will try to speed up things by only copying the metadata in the filecache. This breaks the encryption, as the encryption key depends on the path of the file and isn't being moved in this case, nor any re-encryption happens for the new path. Before #62255, the user might be even served the raw file with the ciphertext in some cases.

To fix the issue, I'll let the global functions handle those cases rather then try to duplicate any logic into the object storage overwrite.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@DerDreschner

DerDreschner commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable33

@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable32

@DerDreschner DerDreschner self-assigned this Jul 21, 2026
@DerDreschner
DerDreschner enabled auto-merge July 21, 2026 13:43
@DerDreschner DerDreschner added bug and removed bug labels Jul 21, 2026
@DerDreschner
DerDreschner requested review from artonge and susnux July 22, 2026 14:54
… unencrypted folders within the same object storage

Assisted-by: ClaudeCode:claude-opus-4-8
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
@DerDreschner
DerDreschner force-pushed the fix/prevent-s3-corruption branch from 54078e2 to 672542f Compare July 24, 2026 10:44
@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport! to stable32

@come-nc come-nc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The explanation makes sense but I’m unsure about the performance cost here.
I’m also unsure I understand the change in Common.php

ping @icewind1991 could you review this?

@DerDreschner

Copy link
Copy Markdown
Contributor Author

@come-nc : The performance cost isn't small, as it needs to pull the file from storage, encrypt it and push it unencrypted. But I don't see any other way to handle that case honestly... It also happens on other storage backends already, so...

I'm also unsure I understand the change in Common.php

That change is necessary as there would be duplicate files otherwise (the original one and the copied/moved one), as it tries to use the same fileId to prevent writing a new file to the bucket. But that doesn't work in this case.

@DerDreschner
DerDreschner merged commit 1ba2971 into master Aug 7, 2026
230 of 232 checks passed
@DerDreschner
DerDreschner deleted the fix/prevent-s3-corruption branch August 7, 2026 12:26
@backportbot

This comment was marked as outdated.

@DerDreschner

Copy link
Copy Markdown
Contributor Author

/backport to stable32

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants