Skip to content

Commit 11542d0

Browse files
sentry-junior[bot]junior
andauthored
feat(project): increase securityTokenHeader max_length from 20 to 64 (#112483)
## Summary Increases the `securityTokenHeader` field limit from 20 to 64 characters in the project settings serializer. The previous 20-char cap was too restrictive — common header names like `X-Custom-Security-Header` (26 chars) hit the limit. 64 is a more practical ceiling that still constrains unbounded input. ## Changes - `src/sentry/core/endpoints/project_details.py`: `max_length=20` → `max_length=64` on `securityTokenHeader` field - `tests/sentry/core/endpoints/test_project_details.py`: adds `test_security_token_header_max_length` covering: - exactly 64 chars accepted (boundary) - 65 chars rejected with 400 Test pattern matches prior art in the same test class (e.g. `test_sensitive_fields_too_long`, `test_store_crash_reports_exceeded`). Co-authored-by: junior <junior@sentry.io>
1 parent 2d83299 commit 11542d0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/sentry/core/endpoints/project_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class ProjectAdminSerializer(ProjectMemberSerializer):
229229
r"^[-a-zA-Z0-9+/=\s]+$", max_length=255, allow_blank=True
230230
)
231231
securityTokenHeader = serializers.RegexField(
232-
r"^[a-zA-Z0-9_\-]+$", max_length=20, allow_blank=True
232+
r"^[a-zA-Z0-9_\-]+$", max_length=64, allow_blank=True
233233
)
234234
verifySSL = serializers.BooleanField(required=False)
235235

tests/sentry/core/endpoints/test_project_details.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,20 @@ def test_security_token_header(self) -> None:
844844
assert self.project.get_option("sentry:token_header") == ""
845845
assert resp.data["securityTokenHeader"] == ""
846846

847+
def test_security_token_header_max_length(self) -> None:
848+
# exactly 64 characters should succeed
849+
value = "X-" + "A" * 62
850+
assert len(value) == 64
851+
resp = self.get_success_response(self.org_slug, self.proj_slug, securityTokenHeader=value)
852+
assert self.project.get_option("sentry:token_header") == value
853+
assert resp.data["securityTokenHeader"] == value
854+
855+
# 65 characters should fail
856+
resp = self.get_error_response(
857+
self.org_slug, self.proj_slug, securityTokenHeader="X-" + "A" * 63, status_code=400
858+
)
859+
assert b"securityTokenHeader" in resp.content
860+
847861
def test_verify_ssl(self) -> None:
848862
resp = self.get_success_response(self.org_slug, self.proj_slug, verifySSL=False)
849863
assert self.project.get_option("sentry:verify_ssl") is False

0 commit comments

Comments
 (0)