Skip to content

Redact scalar instance values from binding diagnostics - #355

Closed
koriym wants to merge 1 commit into
ray-di:2.xfrom
koriym:redact-instance-secrets
Closed

koriym wants to merge 1 commit into
ray-di:2.xfrom
koriym:redact-instance-secrets

Conversation

@koriym

@koriym koriym commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Instance::__toString() renders a bound scalar's literal value. Every surface that stringifies a dependency inherits this: the Bindings section (ModuleString), the Provenance log (Container::add()/merge()), and bindings.md. A toInstance() binding of sensitive data (e.g. an app binding its env config as named scalars) is written to disk in plaintext. CWE-532 (insertion of sensitive information into a diagnostics artifact).

Fix

  • Instance::__toString(): scalar values render as a bare type tag ((string)), same as the existing array/NULL branches. No value is interpolated.
  • BindingsMarkdown::SIGNATURE_VERSION: 2 → 3, to invalidate previously cached (unredacted) bindings.md files.

Note: a same-type value change alone no longer invalidates the cache, since the rendered output is unchanged; a type change still does.

Tests

New coverage in tests/di/BindingsMarkdownTest.php for redaction in the Bindings section and its provenance bind event, the replace event, and the merge() kept/discarded path — each asserting the exact rendered Provenance line rather than a substring the summary header would also satisfy. tests/di/ModuleTest.php golden updated. composer tests passes (304/304).

Summary by CodeRabbit

  • Bug Fixes
    • Sensitive scalar values are no longer exposed in binding diagnostics or provenance output; only their types are shown.
    • Binding documentation is regenerated when a binding’s resolved type changes.
  • Tests
    • Added coverage for redaction across direct, replaced, and merged bindings.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 85d76934-6c12-439d-a188-f7d5569827f7
Commits

Reviewing files that changed from the base of the PR and between a837ba4 and 501f9e5.

Files selected for processing: 5
  • CHANGELOG.md
  • src/di/BindingsMarkdown.php
  • src/di/Instance.php
  • tests/di/BindingsMarkdownTest.php
  • tests/di/ModuleTest.php

No actionable comments were generated in the recent review.

Walkthrough

Scalar values from toInstance() bindings are no longer shown in diagnostics. Output retains only the value type. Cache signatures and tests were updated to cover bindings, provenance, replacements, and merges.

Changes: Scalar diagnostic redaction

Layer / File(s) Summary
Diagnostic rendering and cache invalidation
src/di/Instance.php, src/di/BindingsMarkdown.php
Instance::__toString() renders scalar values by type only. The bindings signature version increases from 2 to 3.
Redaction and cache behavior validation
tests/di/BindingsMarkdownTest.php, tests/di/ModuleTest.php, CHANGELOG.md
Tests cover bindings, provenance, replacements, merge collisions, and cache invalidation. The changelog records the fix.

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 501f9

Scalar values are redacted from diagnostics and existing cached diagnostic files are regenerated, with no concrete merge-blocking risk identified.

Pre-merge checks: Passed 4
Check name Status Explanation
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Redact scalar instance values from binding diagnostics" matches the main change. Instance::__toString() now renders scalar values as type-only tags, such as (string), so bound scalar values…
Full details: Title check

Explanation

The title "Redact scalar instance values from binding diagnostics" matches the main change. Instance::__toString() now renders scalar values as type-only tags, such as (string), so bound scalar values no longer appear in binding diagnostics, provenance logs, or bindings.md. The title is short, specific, and uses the same term as the PR objectives.

Finishing Touches
🧪 Generate unit tests (beta)
  • 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
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 97a367b5-eb05-46f1-8af5-447409c29b80

📥 Commits

Reviewing files that changed from the base of the PR and between a837ba4 and 501f9e5.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • src/di/BindingsMarkdown.php
  • src/di/Instance.php
  • tests/di/BindingsMarkdownTest.php
  • tests/di/ModuleTest.php
💤 Files with no reviewable changes (1)
  • src/di/Instance.php

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a837ba4) to head (501f9e5).
⚠️ Report is 5 commits behind head on 2.x.

Additional details and impacted files
@@             Coverage Diff             @@
##                 2.x      #355   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       434       433    -1     
===========================================
  Files             51        51           
  Lines           1131      1126    -5     
===========================================
- Hits            1131      1126    -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Instance::__toString() rendered a bound scalar's literal value. Every
binding-diagnostics surface that stringifies a dependency -- ModuleString
(the Bindings section, and AbstractModule::__toString()) and the
Provenance log recorded at Container::add()/Container::merge() -- writes
that plaintext value out wherever those diagnostics land, including the
composition-time bindings.md. The same string was also one of the inputs
hashed into BindingsMarkdown's cache signature; only the digest is
persisted there, not the value itself, but the rendered surfaces above do
persist it in plaintext.

Changes:
- Instance::__toString(): collapse the scalar branch into the existing
  type-only branch already used for array/NULL. Every non-object value
  now renders as a bare type tag; the object branch (class name only) is
  unchanged.
- BindingsMarkdown::SIGNATURE_VERSION: 2 -> 3 -- the rendered format
  changed, so this invalidates previously cached bindings.md files (which
  may themselves contain the plaintext leak) on next boot.

One behavioral note: a same-type scalar value change no longer
invalidates the cache on its own, since the rendered output is now
identical either way; a type change still does.

Tests: tests/di/BindingsMarkdownTest.php and tests/di/ModuleTest.php --
new tests cover redaction in the Bindings section and its provenance
"bind" event, the "replace" event, and the merge() kept/discarded
collision path, each asserting the exact rendered Provenance line rather
than a substring that the summary header would also satisfy; the existing
cache-invalidation test is reworked around a type change.

composer tests passes (cs, psalm, phpstan, phpunit -- 304/304, 0
failures).
@koriym
koriym force-pushed the redact-instance-secrets branch from c4ceb42 to 501f9e5 Compare September 17, 2026 19:09
@koriym
koriym marked this pull request as ready for review September 17, 2026 21:56
@koriym

koriym commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@koriym

koriym commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

toInstance($val) で束縛した$valをセキュリティのために残さない、というPRです。

@koriym
koriym marked this pull request as draft September 18, 2026 03:55
@koriym
koriym marked this pull request as ready for review November 4, 2026 00:40

koriym commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 31 minutes.

@koriym

koriym commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Closing in favour of #362. Redacting every scalar also hides non-secret values that the diagnostics exist to show, and the library cannot tell which scalar is a secret. A value bound through a provider never reaches bindings.md, (string) $module or a serialized Injector; #362 adds EnvProvider for that, pins it with a test, and binds the demo password that way.

@koriym koriym closed this Dec 1, 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