Skip to content

fix: trim userinfo to mapped fields before storing in session cookie#141

Merged
hrntknr merged 1 commit intosigbit:mainfrom
healqq:fix/trim-userinfo-to-mapped-fields
Apr 13, 2026
Merged

fix: trim userinfo to mapped fields before storing in session cookie#141
hrntknr merged 1 commit intosigbit:mainfrom
healqq:fix/trim-userinfo-to-mapped-fields

Conversation

@healqq
Copy link
Copy Markdown
Contributor

@healqq healqq commented Apr 11, 2026

Summary

  • OIDC providers like Keycloak include roles, groups, and other claims in the userinfo response regardless of requested scopes. The full response is stored in the session cookie via gorilla/securecookie, which has a 4096-byte hard limit. This causes securecookie: the value is too long errors for any provider with a non-trivial number of claims.
  • This PR derives the needed top-level keys from --header-mapping and --oidc-user-id-field, then filters the userinfo map before saving it to the session. When no mapping is configured, the full response is preserved (backwards-compatible).

Changes

  • pkg/auth/auth.goNewAuthRouter accepts userInfoFields []string; filterUserInfo() strips unneeded keys before session storage
  • pkg/mcp-proxy/main.gouserInfoFieldsFromConfig() extracts top-level keys from JSON pointer config flags
  • Tests for filtering logic, config extraction, and full OAuth flow integration

Test plan

  • go test ./... passes
  • Unit tests for filterUserInfo (specified keys, missing keys, empty/nil input)
  • Unit tests for userInfoFieldsFromConfig (JSON pointers, nested paths, dedup, empty config)
  • Integration test: mock provider returns bloated userinfo → session only contains filtered fields
  • Integration test: nil filter preserves full userinfo (backwards compat)

🤖 Generated with Claude Code

The OIDC callback stores the full userinfo response from the provider
in a cookie-based session. Providers like Keycloak include roles,
groups and other claims regardless of requested scopes, easily
exceeding gorilla/securecookie's 4096-byte limit.

Derive the needed top-level keys from --header-mapping and
--oidc-user-id-field, then strip everything else before saving to
the session. This keeps the cookie small while preserving all data
needed for header forwarding and JWT claims.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@healqq
Copy link
Copy Markdown
Contributor Author

healqq commented Apr 13, 2026

@hrntknr hello!
Will you have time to have a look at this one? It's currently a blocker for my use-case, and I can't easily work around it.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@hrntknr hrntknr left a comment

Choose a reason for hiding this comment

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

Thank you, this approach seems very appropriate.

@hrntknr hrntknr merged commit 683d79a into sigbit:main Apr 13, 2026
8 checks passed
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