From 42609eab021952e5f48f58a910bddec3db290a0b Mon Sep 17 00:00:00 2001 From: Bardi Harborow Date: Wed, 4 Nov 2026 21:26:16 +1100 Subject: [PATCH] fix: Return M_KEY_TOO_LARGE for oversize profile keys Profile keys longer than 255 bytes were rejected with 413 M_TOO_LARGE. The spec requires 400 M_KEY_TOO_LARGE, which ruma now provides. --- changelog.d/2451.bugfix.1.md | 1 + src/service/users/profile.rs | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) create mode 100644 changelog.d/2451.bugfix.1.md diff --git a/changelog.d/2451.bugfix.1.md b/changelog.d/2451.bugfix.1.md new file mode 100644 index 000000000..c102c6bd5 --- /dev/null +++ b/changelog.d/2451.bugfix.1.md @@ -0,0 +1 @@ +Setting a profile key longer than 255 bytes now returns 400 `M_KEY_TOO_LARGE` as required by the spec, instead of 413 `M_TOO_LARGE`. diff --git a/src/service/users/profile.rs b/src/service/users/profile.rs index 954b0eac4..b2c0c3e3b 100644 --- a/src/service/users/profile.rs +++ b/src/service/users/profile.rs @@ -51,12 +51,8 @@ impl super::Service { let field_name = change.field_name(); - // TODO: The spec mentions special error codes (M_PROFILE_TOO_LARGE, - // M_KEY_TOO_LARGE) for profile field size limits, but they're not in - // its list of error codes and Ruma doesn't have them. Should we - // return those, or is M_TOO_LARGE okay? if field_name.as_str().len() > MAX_KEY_LENGTH_BYTES { - return Err!(Request(TooLarge( + return Err!(Request(KeyTooLarge( "Individual profile keys must not exceed {MAX_KEY_LENGTH_BYTES} bytes in length." ))); }