Skip to content

fix(desktop): attest proxy before sending admin token - #594

Open
luvs01 wants to merge 1 commit into
devfrom
codex/propose-fix-for-admin-token-leak
Open

luvs01 wants to merge 1 commit into
devfrom
codex/propose-fix-for-admin-token-leak

Conversation

@luvs01

@luvs01 luvs01 commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a local attacker that binds the discovered loopback port from provoking the desktop to disclose the file-backed admin token by returning a 401 and capturing the retry.
  • Ensure the desktop only releases the reusable management credential after the peer proves process-bound identity (PID/port) via the existing local HMAC attestation protocol.

Description

  • Add Auth::runtime_identity() that loads the protected runtime-port.json (pid/port/attestation secret) and validate its shape before use in the desktop client (desktop/src-tauri/src/auth.rs).
  • Before retrying a 401 with the admin token, call authenticate_target() to issue an x-opencodex-attestation-challenge to /healthz and verify the returned HMAC proof, service, pid, port, and that the runtime record remains unchanged (desktop/src-tauri/src/proxy.rs).
  • Implement constant-time HMAC verification using hmac + sha2 and Base64URL decoding to match the server attestation primitive and map request errors cleanly (desktop/src-tauri/src/proxy.rs).
  • Add a focused unit test asserting proof binding to the recorded runtime identity and add the required Rust deps to desktop/src-tauri/Cargo.toml (base64, hmac, sha2).

Testing

  • Ran bun run typecheck, which passed.
  • Ran cargo fmt --manifest-path desktop/src-tauri/Cargo.toml -- --check and git diff --check, which passed, and committed the changes.
  • Ran bun run privacy:scan, which passed.
  • Attempted cargo check --manifest-path desktop/src-tauri/Cargo.toml, which was blocked by the environment missing glib-2.0.pc required by Tauri on this CI container (external system dependency), so desktop cargo check could not complete here.
  • Ran bun run test until environment-driven server-test expectations diverged (existing unrelated failures where some fixtures returned 403 vs expected 401); many test cases executed and passed earlier in the run but the full suite was not completed in this environment.

Codex Task


Devin Review

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository: luvs01/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 33afac27-de7a-435f-af36-899c5b590ec5


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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-21T01:30:11.047935Z f91d022 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.

@github-actions github-actions Bot added the bug Something isn't working label Sep 21, 2026
@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment on lines +150 to +154
};
mac.update(
format!(
"opencodex-local-management-v1\n{challenge}\n{}\n{}",
identity.pid, identity.port

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Authenticated desktop requests always fail against the real proxy

The verifier decodes the Base64URL secret, but the server signs with the secret’s UTF-8 bytes. Every genuine proof fails, disabling authenticated tray, widget, and stop requests.

Learn more

The server passes the Base64URL text directly to Node’s createHmac, so that text’s UTF-8 bytes are the HMAC key. Rust currently decodes the text into the underlying 32 random bytes, producing a different key and digest. The added unit vector matches Rust’s decoded-key behavior, not the server protocol in createLocalAttestationProof.

Example: For secret BwcH...Bwc, challenge AAAA...AAA, PID 4242, and port 10100, the server produces Yr9EKHjeAFfsFMsF8Xsd7J6LxBYnObweKZlLyTMk0Lo. This verifier and its test expect T2FWKlQv-CS_ygbwmxZ5QRJtpqmM7J8i4IQ_LEaW1vg, so desktop authentication rejects the running proxy.

Recommended fix: Initialize Hmac<Sha256> with identity.attestation_secret.as_bytes() without Base64URL-decoding the secret. Update the test vector to one generated by the TypeScript server primitive, while continuing to Base64URL-decode the returned proof before constant-time verification.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +82 to 84
self.authenticate_target().await?;
let token = self.auth.token().ok_or(ProxyError::Unauthorized)?;
let response = self.send(&method, path, Some(token)).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Explicit security review is required before merge

This PR changes admin-token handling and an authentication boundary. Repository policy requires explicit security review and maintainer sponsorship before merge.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f91d022243

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +145 to +148
let Ok(secret) = URL_SAFE_NO_PAD.decode(&identity.attestation_secret) else {
return false;
};
let Ok(mut mac) = Hmac::<Sha256>::new_from_slice(&secret) else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use the encoded secret bytes as the HMAC key

For every authenticated desktop request, this decodes the 43-character Base64URL secret before constructing the HMAC, but the server's createLocalAttestationProof calls createHmac("sha256", secret) and therefore uses the encoded string's UTF-8 bytes directly. The resulting proofs never match, so /api/* retries fail with Unauthorized and the tray, widget, and Stop Proxy action lose management access; the unit test currently hard-codes a proof from the incompatible decoded-key algorithm. Construct the HMAC from identity.attestation_secret.as_bytes() (or change both protocol implementations together).

AGENTS.md reference: AGENTS.md:L420-L426

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant