Skip to content

fix(utils): normalize URL to host before hashing credential storage key - #525

Closed
AntonYeromin wants to merge 1 commit into
mainfrom
fix/sso-credential-url-normalization
Closed

fix(utils): normalize URL to host before hashing credential storage key#525
AntonYeromin wants to merge 1 commit into
mainfrom
fix/sso-credential-url-normalization

Conversation

@AntonYeromin

Copy link
Copy Markdown
Collaborator

Summary

codemie profile login --url <api-url> and codemie setup derived different SHA-256 storage keys for the same CodeMie origin, because credential storage hashed the raw URL while retrieval normalized it to protocol//host first. Logging in via codemie profile login --url https://host/code-assistant-api stored credentials under one key, but the proxy's lookup (via the normalized host) used a different key, so codemie-claude reported "SSO credentials not found" immediately after a successful login.

Changes

  • Move URL normalization (reduce to protocol//host before hashing) into CredentialStore.getUrlStorageKey() in src/utils/security.ts, so it is the single point of normalization shared by every SSO and JWT store/retrieve/clear operation.
  • This also fixes the same latent asymmetry in the JWT credential path, which had no normalization anywhere previously.

Testing

  • Tests added/updated — none added; existing tests/integration/sso-per-url-credentials.test.ts (23 tests) already covers per-URL storage/retrieval and passes against the fix.
  • Manual testing done — verified with a hash-comparison script that store/retrieve keys now match for https://codemie-preview.lab.epam.com/code-assistant-api (previously mismatched).

Checklist

  • Code follows project standards
  • CI is green (npm run ci)
  • No merge conflicts with main

CredentialStore.getUrlStorageKey() only lowercased and trimmed a
trailing slash, so the storage key depended on whatever URL path a
caller happened to pass. CodeMieSSO.getStoredCredentials() (used by
the proxy on startup) normalizes to protocol+host before deriving its
lookup key, but CodeMieSSO.authenticate() stored credentials keyed by
the raw, unnormalized URL. Running `codemie profile login --url
<api-url-with-path>` therefore stored credentials under a key the
proxy could never find, surfacing "SSO credentials not found" even
immediately after a successful login. `codemie setup` avoided the bug
only because it prompts for the bare portal URL.

Normalizing inside getUrlStorageKey makes every caller (SSO store/
retrieve/clear and JWT store/retrieve/clear) agree on the same key
regardless of path.
@AntonYeromin AntonYeromin changed the title fix(utils): normalize URL to host before hashing credential storage key EPMCDME-14132: fix(utils): normalize URL to host before hashing credential storage key Sep 2, 2026
@AntonYeromin AntonYeromin changed the title EPMCDME-14132: fix(utils): normalize URL to host before hashing credential storage key fix(utils): normalize URL to host before hashing credential storage key Sep 2, 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.

1 participant