Skip to content

HELIO-5072 chop very long UA strings for COUNTER session#3989

Open
sethaj wants to merge 1 commit into
masterfrom
hotfix/HELIO-5072/facebook-500s
Open

HELIO-5072 chop very long UA strings for COUNTER session#3989
sethaj wants to merge 1 commit into
masterfrom
hotfix/HELIO-5072/facebook-500s

Conversation

@sethaj
Copy link
Copy Markdown
Member

@sethaj sethaj commented May 21, 2026

This is Hotfix 4.37.1 in production

Copilot AI review requested due to automatic review settings May 21, 2026 16:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces dynamic truncation of COUNTER session user-agent strings to ensure the generated session value fits the DB column limit (255 chars), addressing overly long UA strings seen from some clients.

Changes:

  • Cap the user-agent portion of the session string based on the requester IP length so the full session stays within 255 characters.
  • Add specs covering oversized UA handling and validating the computed UA max length across IPv4/IPv6 cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
app/services/counter_service.rb Truncates UA when building COUNTER session strings and adds helper constants/method for max-length calculation.
spec/services/counter_service_spec.rb Adds regression specs ensuring sessions remain ≤ 255 chars and validates UA max-length computation.

Comment on lines 83 to 84
date = DateTime.now.strftime('%Y-%m-%d')
hour = DateTime.now.hour
Comment on lines +120 to +123
it "truncates the user agent based on IP length so the session fits in 255 chars" do
session = described_class.from(controller, fs_presenter).session
expect(session.length).to be <= 255
end
Comment on lines +142 to +151
it "produces a session no longer than 255 chars for any combination" do
[
["1.1.1.1", "A" * 300],
["111.111.111.111", "B" * 300],
["2001:0db8:85a3:0000:0000:8a2e:0370:7334", "C" * 300]
].each do |ip, ua|
truncated_ua = ua[0, service.ua_max_length(ip)]
session = "#{ip}|#{truncated_ua}|2020-10-17|23"
expect(session.length).to be <= 255, "session was #{session.length} chars for IP #{ip}"
end
@sethaj sethaj changed the title HELIO-5072 chop obnoxiously long UA strings for COUNTER session HELIO-5072 chop very long UA strings for COUNTER session May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants