Skip to content

fix(security): PHI render-policy deny-unknown — irc fail-open closed, first-party allowlist enforcement - #62

Merged
supmo668 merged 2 commits into
mainfrom
mangyinm/fix-irc-phi-denylist-deny-unknown
Jul 13, 2026
Merged

supmo668 merged 2 commits into
mainfrom
mangyinm/fix-irc-phi-denylist-deny-unknown

Conversation

@supmo668

@supmo668 supmo668 commented Jul 13, 2026 •

Copy link
Copy Markdown

SEC fix (CTO-ordered, immediate): isThirdPartyChannel flips from denylist-membership to a FIRST_PARTY_PHI_CHANNELS allowlist — a channel is PHI-denied unless explicitly first-party, so irc AND any unknown/future channel is refused at runtime (safe-by-default). KNOWN_THIRD_PARTY_CHANNELS becomes documentation; the allowlist is enforcement. Behaviorally verified: phiApproved-irc → MINIMIZED. Pins: deny-unknown, CHAT_CHANNEL_ORDER registry completeness, regression guard. 5 red-first tests → green; 65 pass; tsgo+oxlint clean; 2-reviewer QG (security SOUND, correctness CORRECT). Matrix demotion follows separately per CTO ruling.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Security Enhancements
    • Strengthened health-information protection by allowing approval only for explicitly recognized first-party channels.
    • Unknown and third-party channels are now automatically treated as restricted, even when configured for approval.
    • Continued support for approved first-party channels while preventing sensitive health content from appearing in restricted channels.

…th deny-unknown posture (CTO openclaw#3578)

SECURITY (PHI boundary). B5 render-policy's KNOWN_THIRD_PARTY_CHANNELS was an explicit DENYLIST that omitted 'irc' — so an operator could put 'irc' (or any unlisted/future channel) in phiApprovedChannels and leak a health-bearing ui.summary. A runtime fail-open, not just a lint gap.

FIX (deny-unknown posture, per CTO openclaw#3578): flip isThirdPartyChannel from denylist-membership to a FIRST_PARTY_PHI_CHANNELS allowlist — a channel is third-party (PHI-denied) UNLESS explicitly first-party {shrinemobile, webchat, matrix}. So irc AND any unknown/future channel is REFUSED AT RUNTIME (not merely linted); a newly-added channel is safe-by-default (denied) until deliberately allowlisted. Added 'irc' to KNOWN_THIRD_PARTY_CHANNELS (now documentation only; the allowlist is enforcement).

Red-first: 5 new SEC-IRC tests went red→green — incl. the BEHAVIORAL pin (a phiApproved-irc config → minimized, no health leak), a deny-unknown pin (arbitrary unknown channel refused), a CHAT_CHANNEL_ORDER registry-completeness assertion (no core channel can be first-party by omission), and a regression guard (shrinemobile/webchat/matrix stay approvable). 65 tests pass (render-policy 29 + deliver 36, zero regression), tsgo clean, oxlint clean.

QG: 2-reviewer (security + correctness). Security: SOUND, no CRIT/HIGH/MED — deny-unknown closes the fail-open at runtime for irc/unknown/case-variants, all asymmetries fail-closed. Correctness: CORRECT, no findings. Both LOW/INFO notes applied (tightened the KNOWN_THIRD_PARTY_CHANNELS docstring to reflect it's documentation not enforcement; moved the CHAT_CHANNEL_ORDER import to the top).

FOLLOW-UP (CTO openclaw#3581, separate): demote matrix to third-party (federated protocol, counsel-gate class) → first-party = {shrinemobile, webchat}. Precondition verified: no live config depends on matrix-PHI (only a test). Lands next under the same deny-unknown completeness pin.

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

PHI channel posture

Layer / File(s) Summary
First-party allowlist classification
src/infra/outbound/render-policy.ts
Adds an explicit first-party PHI allowlist and classifies unknown or non-allowlisted channels as third-party at runtime.
Deny-unknown policy validation
src/infra/outbound/render-policy.test.ts
Tests minimized rendering for denied channels, registry completeness, first-party regressions, and sanitization behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A bunny checks each channel’s name,
Unknown paths receive no claim.
Approved friends may safely stay,
IRC’s health text fades away.
Allowlists guard the burrow bright—
PHI sleeps safely through the night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description states the core fix, but it does not follow the required template and omits most required sections. Resubmit using the template and add the required Summary, Change Type, Scope, Linked Issue/PR, Security Impact, Verification, Evidence, and Risk sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main security change: switching PHI render-policy enforcement to a first-party allowlist and denying unknown channels.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mangyinm/fix-irc-phi-denylist-deny-unknown

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.

@github-actions

Copy link
Copy Markdown

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/infra/outbound/render-policy.test.ts`:
- Around line 261-310: Extend the “REGRESSION: first-party surfaces” test around
isThirdPartyChannel and sanitizePhiApprovedChannels to cover mixed-case and
whitespace-padded inputs: “ShrineMobile”, “ WEBCHAT ”, and “Matrix” must
normalize as first-party and remain approved. Verify the normalized approved
values and ensure none are incorrectly placed in ignored.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0dcaf1c4-9b25-41ef-9e19-93f90e1c8869

📥 Commits

Reviewing files that changed from the base of the PR and between 7233d52 and 97648ca.

📒 Files selected for processing (2)
  • src/infra/outbound/render-policy.test.ts
  • src/infra/outbound/render-policy.ts

Comment on lines +261 to +310

// ---------------------------------------------------------------------------
// SEC-IRC (CTO #3578): deny-unknown PHI posture. The denylist was NOT complete
// (`irc` omitted) → an operator could phiApprove `irc` and leak PHI. The fix
// hardens the SHAPE: a channel is third-party (PHI-denied) UNLESS explicitly
// first-party, so `irc` AND any unknown/future channel is refused at RUNTIME,
// not merely caught by a lint. These assert the behavioral guarantee.
// ---------------------------------------------------------------------------
describe("SEC-IRC: deny-unknown PHI posture (CTO #3578)", () => {
it("irc is third-party (the omitted-denylist fail-open is closed)", () => {
expect(isThirdPartyChannel("irc")).toBe(true);
expect(KNOWN_THIRD_PARTY_CHANNELS).toContain("irc");
});

it("BEHAVIORAL: a phiApproved-irc config is REFUSED at policy level → minimized (not full summary)", () => {
const descriptor = makeDescriptor({ render: "component", fields: HEALTH_FIELDS });
const plan = planChannelRender(descriptor, "irc", { phiApprovedChannels: ["irc"] });
expect(plan).toEqual({ kind: "text", text: MINIMIZED_HEALTH_CONFIRM_TEXT, minimized: true });
if (plan.kind === "text") {
assertNoHealthLeak(plan.text);
}
});

it("deny-unknown: an unknown/future channel can NEVER be phiApproved via config (runtime, not lint)", () => {
expect(isThirdPartyChannel("some_unknown_channel_xyz")).toBe(true);
const descriptor = makeDescriptor({ render: "component", fields: HEALTH_FIELDS });
const plan = planChannelRender(descriptor, "some_unknown_channel_xyz", {
phiApprovedChannels: ["some_unknown_channel_xyz"],
});
expect(plan).toEqual({ kind: "text", text: MINIMIZED_HEALTH_CONFIRM_TEXT, minimized: true });
});

it("COMPLETENESS: every core registry channel (CHAT_CHANNEL_ORDER) is third-party (no omission possible)", () => {
for (const channel of CHAT_CHANNEL_ORDER) {
expect(
isThirdPartyChannel(channel),
`registry channel '${channel}' must be third-party`,
).toBe(true);
}
});

it("REGRESSION: first-party surfaces (shrinemobile/webchat/matrix) stay approvable", () => {
for (const channel of ["shrinemobile", "webchat", "matrix"]) {
expect(isThirdPartyChannel(channel), `${channel} must stay first-party`).toBe(false);
}
const { approved, ignored } = sanitizePhiApprovedChannels(["irc", "shrinemobile"]);
expect(approved).toEqual(["shrinemobile"]);
expect(ignored).toEqual(["irc"]);
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1. Verify CHAT_CHANNEL_ORDER contents — should include known third-party channels and exclude first-party
rg -n "CHAT_CHANNEL_ORDER" src/channels/ -A 15 --type ts

# 2. Confirm CHAT_CHANNEL_ORDER does not contain first-party channels
rg -n "CHAT_CHANNEL_ORDER" src/channels/ -A 15 --type ts | rg -i "shrinemobile|webchat|matrix"

Repository: Syntropy-Health/openclaw

Length of output: 9146


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== render-policy.test.ts relevant section =="
sed -n '1,360p' src/infra/outbound/render-policy.test.ts

echo
echo "== channel registry normalization + first-party helpers =="
sed -n '1,220p' src/channels/registry.ts

echo
echo "== search for third-party classification helpers =="
rg -n "isThirdPartyChannel|sanitizePhiApprovedChannels|normalizeChannelName|normalizeChannelKey|KNOWN_THIRD_PARTY_CHANNELS|FIRST_PARTY|third-party" src -g '*.ts'

Repository: Syntropy-Health/openclaw

Length of output: 25125


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== render-policy.ts =="
sed -n '1,240p' src/infra/outbound/render-policy.ts

echo
echo "== render-policy tests around normalization =="
sed -n '160,230p' src/infra/outbound/render-policy.test.ts

Repository: Syntropy-Health/openclaw

Length of output: 12357


Add first-party normalization coverage
Existing normalization tests cover denylisted inputs, but first-party channels should also be exercised with mixed case/whitespace (ShrineMobile, WEBCHAT, Matrix) so a regression in normalizeChannelName doesn’t silently break the allowlist.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/infra/outbound/render-policy.test.ts` around lines 261 - 310, Extend the
“REGRESSION: first-party surfaces” test around isThirdPartyChannel and
sanitizePhiApprovedChannels to cover mixed-case and whitespace-padded inputs:
“ShrineMobile”, “ WEBCHAT ”, and “Matrix” must normalize as first-party and
remain approved. Verify the normalized approved values and ensure none are
incorrectly placed in ignored.

supmo668 added a commit that referenced this pull request Jul 13, 2026
…tree from format:check (#63)

* mangyinm/cto: chore: oxfmt inherited main-branch format debt (14 non-sealed files) — unblocks PR #62 CI check

PR #62 (irc PHI fix) failed the repo-wide oxfmt --check on 16 pre-existing files it does NOT touch — inherited main format debt (oxfmt 0.33.0 version drift). Per CTO openclaw#3585: standalone mechanical oxfmt-only branch off main (7233d52), landed first as a chore so #62 greens clean. Purely mechanical (oxfmt --write, nothing hand-edited): import re-sorting (server-http/server-startup), markdown table alignment (SYN-206 contract + 7 qgr receipts), whitespace (5 test files). Zero logic change. SCOPE NOTE: 14 of the 16 drifted files. The other 2 live under the sealed-referee test tree, which the implementer agent is hook-blocked from touching (correct sealed-TDD discipline) — flagged to CTO separately as a process gap (repo-wide format check vs implementer sealed-tree block).

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>

* mangyinm/cto: chore: exempt the sealed-referee test tree from oxfmt (seal integrity outranks format conformity)

CTO ruling (option B, openclaw#3589): exempt the sealed test tree from oxfmt --check — doctrine. Sealed-referee artifacts are integrity-hash-locked; the sealed form IS the canonical form. A formatter version bump (oxfmt 0.33.0 drift) must never be able to demand churn on a tree the implementer agent is (correctly) hook-barred from touching. This is the only fix that prevents recurrence on every future oxfmt bump. Added the sealed glob to .oxfmtrc.jsonc ignorePatterns with an inline WHY comment. format:check now clean across the repo (4947 files; the 6 sealed artifacts excluded). Completes the #62 CI-check unblock: 14-file mechanical reformat (d1e6aa5) + this exclusion.

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>

* mangyinm/cto: chore: exempt the sealed tree from oxlint (same seal-integrity doctrine) + fix 2 curly errors in the referee runner

CTO openclaw#3592: the type-aware oxlint pass surfaced 6 inherited tool-drift errors — 4 inside the sealed-referee tree (template-expression + spread lints) and 2 curly errors in scripts/run-sealed-referee.mjs (non-sealed runner).

Applied the SAME doctrine consistently: the sealed tree is exempt from LINT for the same reason it's exempt from format — seal integrity outranks style conformity; a linter version bump must never demand churn on a hash-locked tree the implementer agent is (correctly) barred from touching. Added the sealed glob to .oxlintrc.json ignorePatterns with an inline JSONC WHY comment (matching the .oxfmtrc exemption).

The referee runner script is NOT sealed → fixed its 2 curly errors properly (added braces to the single-line if/else-if at the RESULT pass/fail logging). VERIFIED: pnpm lint (oxlint --type-aware) now clean — 0 warnings, 0 errors across 3213 files, config parses. Completes the #63 chore (format exemption + lint exemption + curly fix).

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>

* mangyinm/cto: chore: fix 5 pre-existing broken doc-links in identity-scoped-memory.md (extension source refs → inline-code)

CTO openclaw#3594 round 3: check-docs surfaced 5 broken relative links (identity-scoped-memory.md lines 621-625) — pre-existing, only ran because the chore reformatted md. The 5 targets (persist-user-identity/IDENTITY_CONTRACT.md, auth-memory-gate/README.md + MEMORY_SCOPE_CONTRACT.md, memory-graphiti/README.md, persist-postgres/openclaw.plugin.json) all EXIST in the repo but live OUTSIDE the published docs tree, so docs-link-audit.mjs (which resolves against DOCS_DIR) correctly reports 'relative file not found' — a relative link from a published doc can never reach the source tree.

FIX: converted the 5 broken relative links to INLINE-CODE path references (the established convention — docs/tools/plugin.md:648 already refs extension source this way, e.g. ). Preserves the exact path (reader finds it in the repo), audit-clean (not a link), no external-URL/branch brittleness. Did NOT create stub files (per your instruction). oxfmt re-aligned the table. VERIFIED: pnpm check:docs fully clean — format:docs (639 files), markdownlint (0 errors, 324 files), docs-link-audit (broken_links=0, 2781 checked); repo-wide format:check still clean.

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: cto <[email protected]>
Co-authored-by: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@supmo668
supmo668 merged commit da296db into main Jul 13, 2026
19 of 23 checks passed
@supmo668
supmo668 deleted the mangyinm/fix-irc-phi-denylist-deny-unknown branch July 13, 2026 21:17
supmo668 added a commit that referenced this pull request Jul 13, 2026
…rated messaging is the counsel-gate class (CTO openclaw#3581) (#64)

Follow-up to the deny-unknown PHI fix (#62), under the same completeness pin. CTO openclaw#3581 ruled matrix is NOT first-party: a federated messaging provider is squarely the SEC-4 counsel-gate class ('third-party messaging providers can NEVER be phiApproved'). Removed matrix from FIRST_PARTY_PHI_CHANNELS → first-party = {shrinemobile, webchat} only (the app's own surfaces).

Precondition verified (per CTO): NO live operator config depends on matrix-PHI — matrix only appeared in a single test. Red-first: added a MATRIX-DEMOTED test (isThirdPartyChannel(matrix)===true + behavioral planChannelRender(matrix, phiApproved:[matrix]) → minimized, no health leak) that went red→green. Switched the deliver positive-path test from matrix→webchat (preserves 'first-party channel gets full summary' coverage on a genuine first-party surface). 66 tests pass (render-policy 30 + deliver 36), tsgo clean, oxlint clean.

STRICTLY MORE RESTRICTIVE: this removes an approval, so it can only reduce PHI egress — it cannot create a leak; the deny-unknown mechanism itself (already 2-reviewer-QG'd in #62) is unchanged. A federation-disabled self-hosted homeserver may re-argue first-party later WITH deployment evidence (documented inline).

Generated-With: Claude Code

Co-authored-by: cto <[email protected]>
Co-authored-by: Claude <[email protected]>
supmo668 added a commit that referenced this pull request Jul 14, 2026
…annel denylist, DRY profile markers, RequestSubject boundary comment (openclaw#3630) (#65)

3 code-quality items from the cross-repo architecture review (openclaw#3630), one branch, normal QG:

(1) DELETE KNOWN_THIRD_PARTY_CHANNELS (render-policy.ts): it was an exact reordered copy of registry CHAT_CHANNEL_ORDER, its own comment said it was inert (not enforcement — the deny-unknown FIRST_PARTY_PHI_CHANNELS allowlist is), and its test was tautological. Deleted the export + the tautological test + the SEC-IRC toContain assertion + the test import; verified 0 remaining consumers. The load-bearing registry-completeness test (isThirdPartyChannel===true for every CHAT_CHANNEL_ORDER channel) + the deny-unknown posture are untouched. Negative diff; the doc anchor is now derived from the registry (referenced in the FIRST_PARTY docstring).

(2) DRY the profile markers: profile.ts now EXPORTS OPEN/CLOSE ('[SYNTROPY_PROFILE]' / '[/SYNTROPY_PROFILE]') as the single source of truth; profile-context.test.ts (4 literal sites) + index-injection.test.ts (2 sites) now import + use the consts instead of re-hardcoding — prevents drift if the marker changes. Sealed suites left as-is (and hook-barred from me anyway).

(3) RequestSubject boundary comment (syntropy-mcp/src/index.ts): documented that ExchangeSubject (token-exchange.ts) is the VALIDATED discriminated-union form and toExchangeSubject is the ONLY bridge — never pass a loose RequestSubject to the exchange directly.

90 tests pass (render-policy 28 + deliver 36 + profile-context 24 + index-injection ...), tsgo clean, oxlint clean, oxfmt clean. Off fresh main c48edf0 (post #62/#63/#64).

Generated-With: Claude Code

Co-authored-by: cto <[email protected]>
Co-authored-by: Claude <[email protected]>
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