fix(agent): hash code assets without Web Crypto so AI tools work over non-secure origins - #576
Open
cakelesscoder wants to merge 1 commit into
Open
cakelesscoder wants to merge 1 commit into
cakelesscoder wants to merge 1 commit into
Conversation
… non-secure origins The runtime code-asset tools hashed content with `crypto.subtle.digest`, which is only defined in a secure context (HTTPS or localhost). When the CMS is reached over a LAN/Tailscale IP on plain http:// — a non-secure context — `crypto.subtle` is undefined, so the first code-asset tool call threw "crypto.subtle is undefined" and the agent hung. Add a dependency-free `sha256Hex` (src/core/utils/sha256.ts) that produces the identical 64-char digest in any context, and use it for the read→patch optimistic-concurrency fingerprint. The hash is a self-consistent, client-only fingerprint — never cryptographic-security-bearing — so a pure-JS SHA-256 is a drop-in. New test verifies it byte-for-byte against native WebCrypto across UTF-8 and all padding boundaries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 78dbb7a63251bca132bb5ed58f0b15e179817acf)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The runtime code-asset tools hash content with
crypto.subtle.digest.crypto.subtleonly exists in a secure context — HTTPS orlocalhost.Instatic is self-hosted, so reaching the admin over a LAN or Tailscale IP on plain
http://is an ordinary deployment rather than an edge case. In that contextcrypto.subtleisundefined, so the first code-asset tool call throwscrypto.subtle is undefinedand the agent stops mid-turn.This adds a dependency-free
sha256Hexinsrc/core/utils/sha256.tsand uses it for the read→patch optimistic-concurrency fingerprint incodeAssetTools.ts.That fingerprint is self-consistent and client-only — it answers "did this file change between read and patch" and never bears cryptographic security — so a pure-JS SHA-256 is a drop-in, and it returns byte-identical digests in every context. No new dependency; it's ~100 lines of standard SHA-256.
Verification
bun run buildbun testbun run lintNew test
src/__tests__/utils/sha256.test.tschecks the implementation against native WebCrypto across the empty string and known vectors, multi-byte UTF-8, every message-length residue around the 55/56/64-byte padding boundaries, and single-character sensitivity.Checklist
Split out of a larger branch so it can be reviewed on its own — it's independent of any AI provider and fixes the existing agent tooling on non-secure origins.