Repository navigation
fix(metrics): truncate header-derived values and validate location length on metrics enter/leave - #631
fix(metrics): truncate header-derived values and validate location length on metrics enter/leave#631romanetar wants to merge 3 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-631/ This page is automatically updated on each push to this PR. |
smarcet
left a comment
There was a problem hiding this comment.
@romanetar please review
There was a problem hiding this comment.
🟢 Approval recommended
The implementation consistently addresses the database length failures and includes appropriate regression coverage.
0 open findings
What changed in this PR
Prevents metric insert failures caused by values exceeding VARCHAR(255) limits.
Changes:
- Truncates header-derived metric values safely, including multibyte strings.
- Validates and documents the 255-character location limit.
- Adds boundary and truncation tests.
| File | Description |
|---|---|
SummitMetric.php |
Truncates header-derived values. |
OAuth2SummitMetricsApiController.php |
Validates location length. |
SummitMetricsSchemas.php |
Documents location limits. |
OAuth2SummitMetricsApiControllerTest.php |
Tests truncation and validation boundaries. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-631/ This page is automatically updated on each push to this PR. |
1 similar comment
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-631/ This page is automatically updated on each push to this PR. |
…ngth on metrics enter/leave SummitMetric::build() copied User-Agent, Referer/Origin and Client-IP/X-Forwarded-For unchanged into VARCHAR(255) columns, so a longer value made MySQL reject the INSERT and metrics/enter returned 500. Cut them to 255 characters with mb_substr and limit location to 255 in the enter and leave payloads (412 instead of 500).
…ith 412 location is client metadata like the header derived values. Validating the raw URL-encoded value rejected requests that fit the column once decoded. SummitMetric::setLocation() now cuts the decoded value to 255 characters, the max:255 rules and OpenAPI maxLength are reverted, and the tests assert truncation and that an encoded location decoding under 255 is kept.
SummitMetric.Location is a TEXT column (Version20201016145706), so long values never caused the insert failure. Revert the location truncation and the VARCHAR(255) mapping; only Ip, Origin and Browser are truncated.
b9a5fff to
afa542e
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-631/ This page is automatically updated on each push to this PR. |
ref https://app.clickup.com/t/9014802374/86bcg38nf
Problem
PUT /api/v1/summits/{id}/metrics/enterreturns 500 when theUser-Agentis longer than 255 characters (e.g. Facebook in-app browsers).SummitMetric::build()copies User-Agent, Referer/Origin and Client-IP/X-Forwarded-For unchanged intoVARCHAR(255)columns, so MySQL (strict mode in production) rejects the INSERT withData too long for column 'Browser', the transaction rolls back and the visit is lost. In the 7 days to 2026-10-07, 9 of 16,252 calls failed this way. Thelocationbody field has the same weakness (no length validation, stored inVARCHAR(255)).Changes
SummitMetric: newMaxStringColumnLength = 255constant;ip,originandbrowsergo through a privatetruncate()helper (mb_substr, null-safe) inbuild().lengthis now explicit on the three columns (255 is already the default, so no schema change). One change covers every path, sincebuild()is the only reader of these headers.OAuth2SummitMetricsApiController:locationis nowsometimes|string|max:255, so a too-long location returns 412 instead of 500.maxLength: 255onlocation.Scope note:
leaveincludedThe task only mentions
enter(), butPOST metrics/leavehas the same unvalidatedlocationrule, somax:255andmaxLength: 255are applied there too (SummitMetricLeaveRequest).Tests
New tests in
OAuth2SummitMetricsApiControllerTest:enterwith a 256-char location returns 412, 255 returns 201leavelocation length (256 returns 412, 255 returns 201)Headers are set in
$_SERVER(that is whatUserClientHelperreads) and restored intearDown. CI and local MySQL run non-strict, so the 500 does not reproduce there; the tests assert on thebrowser,originandipfields of the response instead. Without the fix, the header, multibyte,enter412 andleavetests fail; the 255-character ones pass either way as controls. With it, all 10 tests in the class pass.Post-deploy verification
Over 7 days, Loki should show no
Data too long for column 'Browser'lines insummit-api-php, and PUTmetrics/enterwith a User-Agent over 255 characters should return 201 (baseline: 9 of 9 returned 500).Risks
🤖 Generated with Claude Code