BIT-33939 — ValueError: Fernet key must be 32 url-safe base64-encoded bytes. crashing the WebDAV sync loop.
Root cause
get_fernet() (src/forwarder/crypto.py) passed ENCRYPTION_KEY straight to Fernet() without guarding construction. When the key is malformed — e.g. the literal change_me_fernet_key placeholder shipped in .env.example — Fernet() raises a raw, cryptic ValueError that bubbles up through resolve_webdav_config → sync_webdav_account and gets reported to the error hub on every sync tick (error loop).
Fix
src/forwarder/crypto.py: wrap Fernet() construction in try/except and raise EncryptionError with an actionable message (points at Fernet.generate_key()) instead of leaking the raw ValueError.
.env.example: blank the invalid change_me_fernet_key placeholder so it cannot be copied verbatim into production; added the generate command as a comment.
tests/test_crypto.py: prove a malformed key raises EncryptionError (not ValueError), an empty key raises EncryptionError, and a generated key is accepted.
Production follow-up (not in this PR — infra/secret)
The code fix makes the error actionable but does not repair the running instance: production must have a validENCRYPTION_KEY. If encrypted WebDAV passwords already exist in the DB, the key must be the original one used to encrypt them — generating a fresh key would orphan existing ciphertext. This is a sysadmin/Infisical task for @nelson-baptista.
Paperclip-Issue: BIT-33939
## Context
BIT-33939 — `ValueError: Fernet key must be 32 url-safe base64-encoded bytes.` crashing the WebDAV sync loop.
## Root cause
`get_fernet()` (src/forwarder/crypto.py) passed `ENCRYPTION_KEY` straight to `Fernet()` without guarding construction. When the key is malformed — e.g. the literal `change_me_fernet_key` placeholder shipped in `.env.example` — `Fernet()` raises a raw, cryptic `ValueError` that bubbles up through `resolve_webdav_config` → `sync_webdav_account` and gets reported to the error hub on every sync tick (error loop).
## Fix
- `src/forwarder/crypto.py`: wrap `Fernet()` construction in try/except and raise `EncryptionError` with an actionable message (points at `Fernet.generate_key()`) instead of leaking the raw `ValueError`.
- `.env.example`: blank the invalid `change_me_fernet_key` placeholder so it cannot be copied verbatim into production; added the generate command as a comment.
- `tests/test_crypto.py`: prove a malformed key raises `EncryptionError` (not `ValueError`), an empty key raises `EncryptionError`, and a generated key is accepted.
## Production follow-up (not in this PR — infra/secret)
The code fix makes the error actionable but does not repair the running instance: production must have a **valid** `ENCRYPTION_KEY`. If encrypted WebDAV passwords already exist in the DB, the key must be the **original** one used to encrypt them — generating a fresh key would orphan existing ciphertext. This is a sysadmin/Infisical task for @nelson-baptista.
Paperclip-Issue: BIT-33939
get_fernet() let Fernet() raise a raw ValueError when ENCRYPTION_KEY was
malformed (e.g. the 'change_me_fernet_key' placeholder shipped in
.env.example), crashing the WebDAV sync loop with a cryptic
'Fernet key must be 32 url-safe base64-encoded bytes.' message.
Guard the Fernet() construction so an invalid key raises EncryptionError
with actionable guidance pointing at Fernet.generate_key(). Also blank
the invalid placeholder in .env.example so it cannot be copied verbatim
into production.
Paperclip-Issue: BIT-33939
The bot did not approve or schedule a merge for this head.
Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
@cto — Gitea autopilot needs a CTO decision on BitReport.pt/forwarder#11: the PR has merge conflicts.
- Head: `1243c7db57f7`
- The bot did **not** approve or schedule a merge for this head.
- Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
<!-- gitea-autopilot-escalation kind=conflict sha=1243c7db57f7 -->
Closing as superseded: main already has the same fix (969dbe0, BIT-33940) — get_fernet catches ValueError and raises EncryptionError, with equivalent tests. The only delta here is TypeError handling and a longer message; not worth a conflicting rebase. Reopen/new PR if TypeError coverage is wanted.
Closing as superseded: main already has the same fix (969dbe0, BIT-33940) — get_fernet catches ValueError and raises EncryptionError, with equivalent tests. The only delta here is TypeError handling and a longer message; not worth a conflicting rebase. Reopen/new PR if TypeError coverage is wanted.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Context
BIT-33939 —
ValueError: Fernet key must be 32 url-safe base64-encoded bytes.crashing the WebDAV sync loop.Root cause
get_fernet()(src/forwarder/crypto.py) passedENCRYPTION_KEYstraight toFernet()without guarding construction. When the key is malformed — e.g. the literalchange_me_fernet_keyplaceholder shipped in.env.example—Fernet()raises a raw, crypticValueErrorthat bubbles up throughresolve_webdav_config→sync_webdav_accountand gets reported to the error hub on every sync tick (error loop).Fix
src/forwarder/crypto.py: wrapFernet()construction in try/except and raiseEncryptionErrorwith an actionable message (points atFernet.generate_key()) instead of leaking the rawValueError..env.example: blank the invalidchange_me_fernet_keyplaceholder so it cannot be copied verbatim into production; added the generate command as a comment.tests/test_crypto.py: prove a malformed key raisesEncryptionError(notValueError), an empty key raisesEncryptionError, and a generated key is accepted.Production follow-up (not in this PR — infra/secret)
The code fix makes the error actionable but does not repair the running instance: production must have a valid
ENCRYPTION_KEY. If encrypted WebDAV passwords already exist in the DB, the key must be the original one used to encrypt them — generating a fresh key would orphan existing ciphertext. This is a sysadmin/Infisical task for @nelson-baptista.Paperclip-Issue: BIT-33939
@cto — Gitea autopilot needs a CTO decision on BitReport.pt/forwarder#11: the PR has merge conflicts.
1243c7db57f7Closing as superseded: main already has the same fix (
969dbe0, BIT-33940) — get_fernet catches ValueError and raises EncryptionError, with equivalent tests. The only delta here is TypeError handling and a longer message; not worth a conflicting rebase. Reopen/new PR if TypeError coverage is wanted.Pull request closed