zitadel/internal
Tim Möhlmann 3759ed9f08 fix(crypto): reject decrypted strings with non-UTF8 characters. (#8374)
# Which Problems Are Solved

We noticed logging where 500: Internal Server errors were returned from
the token endpoint, mostly for the `refresh_token` grant. The error was
thrown by the database as it received non-UTF8 strings for token IDs

Zitadel uses symmetric encryption for opaque tokens, including refresh
tokens. Encrypted values are base64 encoded. It appeared to be possible
to send garbage base64 to the token endpoint, which will pass decryption
and string-splitting. In those cases the resulting ID is not a valid
UTF-8 string.

Invalid non-UTF8 strings are now rejected during token decryption.

# How the Problems Are Solved

- `AESCrypto.DecryptString()` checks if the decrypted bytes only contain
valid UTF-8 characters before converting them into a string.
- `AESCrypto.Decrypt()` is unmodified and still allows decryption on
non-UTF8 byte strings.
- `FromRefreshToken` now uses `DecryptString` instead of `Decrypt`

# Additional Changes

- Unit tests added for `FromRefreshToken` and
`AESCrypto.DecryptString()`.
- Fuzz tests added for `FromRefreshToken` and
`AESCrypto.DecryptString()`. This was to pinpoint the problem
- Testdata with values that resulted in invalid strings are committed.
In the pipeline this results in the Fuzz tests to execute as regular
unit-test cases. As we don't use the `-fuzz` flag in the pipeline no
further fuzzing is performed.

# Additional Context

- Closes #7765
- https://go.dev/doc/tutorial/fuzz
2024-08-06 13:58:53 +02:00
..
actions feat(actions): allow getting metadata of organizations from user grants (#7782) 2024-04-22 11:34:23 +00:00
activity fix: get orgID when missing on trigger logs (#7555) 2024-03-14 08:49:10 +00:00
admin/repository/eventsourcing feat(cmd): mirror (#7004) 2024-05-30 09:35:30 +00:00
api feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
auth/repository fix: prevent error reason leakage in case of IgnoreUnknownUsernames (#8372) 2024-07-31 14:34:10 +02:00
auth_request/repository fix(login): correctly reload policies on auth request (#7839) 2024-04-24 10:54:55 +02:00
authz fix(oidc): remove MFA requirement on ZITADEL API based on user auth methods (#8069) 2024-06-13 13:55:05 +02:00
command fix(crypto): reject decrypted strings with non-UTF8 characters. (#8374) 2024-08-06 13:58:53 +02:00
config feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
crypto fix(crypto): reject decrypted strings with non-UTF8 characters. (#8374) 2024-08-06 13:58:53 +02:00
database fix: always use pgxpool config if MaxOpenConns isn't set (#8328) 2024-07-22 13:29:09 +02:00
domain fix(crypto): reject decrypted strings with non-UTF8 characters. (#8374) 2024-08-06 13:58:53 +02:00
eventstore refactor(database): exchange connection pool (#8325) 2024-07-22 13:28:57 +02:00
execution feat: add action v2 execution on requests and responses (#7637) 2024-05-04 11:55:57 +02:00
feature perf(import): optimize search for domains claimed by other organizations (#8200) 2024-07-05 09:36:00 +02:00
form refactor: rename package errors to zerrors (#7039) 2023-12-08 15:30:55 +01:00
i18n fix(middleware): init translation messages (#7778) 2024-04-16 15:46:13 +02:00
iam refactor: cleanup unused code (#7130) 2024-01-02 14:26:31 +00:00
id feat(cmd): Added machine ID mode to zitadel start up logs (#8251) 2024-07-16 09:53:57 +00:00
idp fix: encode ldap values to make valid UTF8 (#8210) 2024-06-28 13:46:54 +00:00
integration feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
logstore perf: project quotas and usages (#6441) 2023-09-15 16:58:45 +02:00
migration fix(setup): init projections (#7194) 2024-01-25 17:28:20 +01:00
net perf: project quotas and usages (#6441) 2023-09-15 16:58:45 +02:00
notification fix: sanitize output for email (#8373) 2024-07-31 14:34:07 +02:00
org refactor: cleanup unused code (#7130) 2024-01-02 14:26:31 +00:00
project refactor: cleanup unused code (#7130) 2024-01-02 14:26:31 +00:00
protoc merge main into next 2023-10-19 12:34:00 +02:00
qrcode docs(legal): Updated agreements and policies v2 (#3823) 2022-06-15 08:30:58 +02:00
query feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
renderer fix(login): (re)allow HTML in custom login texts (#7575) 2024-03-15 16:29:10 +01:00
repository feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
static Merge branch 'main' into next 2024-06-21 13:30:08 +02:00
statik chore: initial version of a devcontainer (#6352) 2023-08-15 10:49:05 +02:00
telemetry feat: api v2beta to api v2 (#8283) 2024-07-29 12:50:41 +02:00
test refactor(fmt): run gci on complete project (#7557) 2024-04-03 10:43:43 +00:00
user fix: prevent error reason leakage in case of IgnoreUnknownUsernames (#8372) 2024-07-31 14:34:10 +02:00
v2 fix(v2): correct eventstore query (#8124) 2024-06-15 16:12:21 +03:00
view/repository refactor(fmt): run gci on complete project (#7557) 2024-04-03 10:43:43 +00:00
webauthn fix: allow other users to set up MFAs (#7914) 2024-05-07 05:38:26 +00:00
zerrors fix(crypto): reject decrypted strings with non-UTF8 characters. (#8374) 2024-08-06 13:58:53 +02:00