problem: key rotation for encrypted database values #12389

Open
opened 2026-05-03 02:20:54 +02:00 by Gusted · 0 comments
Gusted commented 2026-05-03 02:20:54 +02:00 (Migrated from codeberg.org)

Does your problem still exist on the latest Forgejo version?

Yes, the problem still exists (tested locally with the latest development version)

About your usage of Forgejo

Contributor of Forgejo
Member of the Forgejo security team.
Self-hosts Forgejo.
Co-Maintainer of Codeberg.org's Forgejo instance.

Problem description

Forgejo encrypt some values in the database via two ways:

  • keying, authored by me. The new way of doing encryption.
  • secret, authored in 2019 in Gitea. Legacy way, has some less nice properties that you don't want for encryption.

Since keying was introduced the usages of secret have been converted to keying. Today only one usage of secret is left:
codeberg.org/forgejo/forgejo@b6658076a9/services/auth/source/ldap/source.go (L80)

If the SECRET_KEY (from which the encryption key is derived) is known via some way, the encrypted values in the database can be decrypted. There's no way in Forgejo to re-encrypt all of these values under a new key.

Moreover, once key rotation is added the following code block is no longer needed.

codeberg.org/forgejo/forgejo@b6658076a9/modules/setting/security.go (L266-L271)

This is issue was created as part of https://floss.social/@forgejo/116494296646568723; it is a long-standing known issue that hasn't previously been documented.

Potential workarounds

No response

Forgejo Version

N/A

Other details about your environment (software names and versions)

N/A

Solutions

Accepted solutions to address this problem will go here

### Does your problem still exist on the latest Forgejo version? Yes, the problem still exists (tested locally with the latest development version) ### About your usage of Forgejo Contributor of Forgejo Member of the Forgejo security team. Self-hosts Forgejo. Co-Maintainer of Codeberg.org's Forgejo instance. ### Problem description Forgejo encrypt some values in the database via two ways: - [keying](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/modules/keying/keying.go), authored by me. The new way of doing encryption. - [secret](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/modules/secret/secret.go), authored in 2019 in Gitea. Legacy way, has some less nice properties that you don't want for encryption. Since keying was introduced the usages of `secret` have been converted to `keying`. Today only one usage of `secret` is left: https://codeberg.org/forgejo/forgejo/src/commit/b6658076a96977cc1bc6d0b141d881d4589b74bf/services/auth/source/ldap/source.go#L80 If the `SECRET_KEY` (from which the encryption key is derived) is known via some way, the encrypted values in the database can be decrypted. There's no way in Forgejo to re-encrypt all of these values under a new key. Moreover, once key rotation is added the following code block is no longer needed. https://codeberg.org/forgejo/forgejo/src/commit/b6658076a96977cc1bc6d0b141d881d4589b74bf/modules/setting/security.go#L266-L271 This is issue was created as part of https://floss.social/@forgejo/116494296646568723; it is a long-standing known issue that hasn't previously been documented. ### Potential workarounds _No response_ ### Forgejo Version N/A ### Other details about your environment (software names and versions) N/A ### Solutions *Accepted solutions to address this problem will go here*
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/forgejo#12389
No description provided.