Skip to content

Refuse a PKCE code as a session - #122

Merged
feruzm merged 1 commit into
mainfrom
fix/refuse-pkce-codes-as-sessions
Nov 15, 2026
Merged

feruzm merged 1 commit into
mainfrom
fix/refuse-pkce-codes-as-sessions

Conversation

@feruzm

@feruzm feruzm commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

A code whose signed_message carries a code_challenge is a PKCE code (hivesigner-api#15). It is meant to be good only through HiveSigner's token exchange, which checks the matching code_verifier. ValidateCode accepted any signed ecency.app code, so an intercepted PKCE code could be used here directly and the verifier check skipped.

IsEcencySession now refuses a signed message with a code_challenge field, whatever its value, before any account is read. Codes and tokens without the field are unchanged.

Required by vision-mobile#3641 (point 4) before the first-party PKCE sign-in is enabled. It does not need to wait for hivesigner-api#15: no client sends such codes yet.

Tests (written first, failed before the change):

  • SessionTokenTests.ACodeCarryingAPkceChallengeIsNotASession: signed codes with a real S256 challenge, a null challenge, and an empty one on a posting token all return no user, and no chain read happens.
  • TokenTypeTests.EverythingElseIsRefused: two more cases for the rule itself.
  • Full suite: 872/872.

CLAUDE.md's list of what ValidateCode refuses now includes this case.

Summary by CodeRabbit

  • Bug Fixes
    • Ecency sessions now reject authorization tokens containing a PKCE challenge, preventing tokens that require HiveSigner’s verifier-based exchange from being accepted by the private API.

A code whose signed message carries a code_challenge is good only through
HiveSigner's token exchange, which checks the matching verifier. This service
never sees the verifier, so accepting such a code would let whoever intercepted
it use it directly.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T11:33:52.125852Z 55fa469 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Refuse PKCE codes as API sessions

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Reject signed messages containing code_challenge so PKCE codes cannot bypass verifier checks.
• Preserve acceptance of Ecency codes and posting tokens without that field.
• Add rejection tests and document the session rule.
Diagram

graph TD
  A["Session request"] --> B["Decode signed message"] --> C{"Ecency session?"} -->|Yes| D["Recover signer"] --> E["Read account keys"] --> F["Validate signer"]
  C -->|No| G["Refuse session"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Validate PKCE verifiers in this API
  • ➕ Could support direct PKCE-code authentication.
  • ➖ Would require a verifier-bearing request and duplicate HiveSigner's token-exchange responsibility.

Recommendation: Keep the early rejection rule. HiveSigner's exchange already verifies the code_verifier, while this API receives no verifier; accepting PKCE codes here would undermine that boundary.

Files changed (4) +25 / -2

Bug fix (1) +7 / -1
PrivateApi.Core.csExclude challenge-bearing messages from sessions +7/-1

Exclude challenge-bearing messages from sessions

• IsEcencySession now refuses any signed message containing the 'code_challenge' key, regardless of its value. The check runs before ValidateCode reads account keys, preventing a PKCE code from bypassing HiveSigner's verifier check.

dotnet/EcencyApi/Handlers/PrivateApi.Core.cs

Tests (2) +15 / -0
SessionTokenTests.csTest PKCE rejection through ValidateCode +13/-0

Test PKCE rejection through ValidateCode

• Adds signed-token cases with a real S256 challenge, a null challenge, and an empty challenge on a posting token. Each must return no user without an account read.

dotnet/EcencyApi.Tests/SessionTokenTests.cs

TokenTypeTests.csTest challenge-field rejection in the session rule +2/-0

Test challenge-field rejection in the session rule

• Adds non-null and null 'code_challenge' cases to the inputs IsEcencySession must refuse.

dotnet/EcencyApi.Tests/TokenTypeTests.cs

Documentation (1) +3 / -1
CLAUDE.mdDocument PKCE-code refusal +3/-1

Document PKCE-code refusal

• Adds codes carrying 'code_challenge' to the documented cases ValidateCode refuses before reading an account. Explains that verifier checking belongs to HiveSigner's token exchange.

CLAUDE.md

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Rejects signed messages containing code_challenge as sessions, regardless of its value.

  • Private API sessions reject signed messages that carry a PKCE challenge.

Reviews (1) · Last reviewed commit: "Refuse a PKCE code as a session" · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Ecency session check now rejects signed messages with a code_challenge. Tests cover challenged code tokens and confirm that validation returns null without reading accounts. The guidance documents that PKCE codes must use HiveSigner’s token exchange.

Changes: PKCE session rejection

Layer / File(s) Summary
Session check and validation
dotnet/EcencyApi/Handlers/PrivateApi.Core.cs, dotnet/EcencyApi.Tests/SessionTokenTests.cs, dotnet/EcencyApi.Tests/TokenTypeTests.cs, CLAUDE.md
IsEcencySession rejects messages with a code_challenge. Tests cover challenged tokens, including null and empty challenge values, and check that validation does not read accounts. The guidance describes the PKCE token exchange requirement.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 55fa4

This change stops a signed PKCE authorization code from being accepted as a session, because this service cannot check the PKCE verifier. Codes and tokens without a code_challenge behave as before, and the tests cover the new refusal. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Refuse a PKCE code as a session" matches the main change. The changeset makes IsEcencySession reject Ecency code and posting signed messages that carry a code_challenge, and the tests cover…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Refuse a PKCE code as a session" matches the main change. The changeset makes IsEcencySession reject Ecency code and posting signed messages that carry a code_challenge, and the tests cover those cases. The title is short, specific, and names the primary behavior change, so a teammate scanning history would understand it.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

A rabbit checks each token’s claim,
A challenged code no longer came.
No account reads begin,
When PKCE marks the token within.
HiveSigner checks the verifier’s name.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00905b2f-1910-4c62-9f51-a61a3f5527f8
Commits

Reviewing files that changed from the base of the PR and between 8918d6a and 55fa469.

Files selected for processing: 4

  • CLAUDE.md
  • dotnet/EcencyApi.Tests/SessionTokenTests.cs
  • dotnet/EcencyApi.Tests/TokenTypeTests.cs
  • dotnet/EcencyApi/Handlers/PrivateApi.Core.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@feruzm
feruzm merged commit 9bd9c62 into main Nov 15, 2026
5 checks passed
@feruzm
feruzm deleted the fix/refuse-pkce-codes-as-sessions branch November 15, 2026 11:54
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