Skip to content

Make every opt-out fail closed (0.4.0) - #40

Merged
dmccoystephenson merged 1 commit into
mainfrom
fix/opt-out-fails-closed
Nov 19, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
fix/opt-out-fails-closed

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Usage reporting must actually stay off when it is turned off. This brings the C# client to the same fail-closed semantics as the Java client 0.8.0 (Stephenson-Software/trace-client-java#51).

Fail-open paths fixed

  • TRACE_USAGE_REPORTING was a deny-list (off/false/0/no): any other non-blank value, e.g. disabled or a typo, left reporting on. It now disables for anything but blank or true/on/yes/1 (case-insensitive, trimmed).
  • DO_NOT_TRACK was an allow-list of opt-outs (1/true/yes): on, y and so on left reporting on. It now disables for anything but blank or 0/false/off/no.
  • An environment that cannot be read (e.g. a SecurityException in a sandbox) was treated as "not opted out". EnvironmentDisables() now returns true in that case, and the constructor reports reason environment; it still never throws.
  • The program's own setting had no fail-closed reader. New TraceClient.AllowsReporting(object): true, or a string true/on/yes/1 (any case, trimmed), allows reporting; null, false, a quoted "false", a typo or a number turns it off. The README examples and the class doc comment now use it.

The client reads no config file of its own with a switch (the install-ID file holds only an ID), so no file-parsing changes were needed.

Version

0.3.0 → 0.4.0 in the file header, TraceClient.Version, the csproj <Version> and the README User-Agent example.

Tests

dotnet test -c Release (net8.0): 162 passed, 0 failed. Tests that pinned fail-open behaviour were updated (EnvironmentDisables_IsTrueWhenTheEnvironmentCannotBeRead, the "leave the program setting in charge" set now only blank or clearly-on values); new cases cover typos in both variables and AllowsReporting for bool, string, null and numbers. The .NET Framework 4.8 leg runs in CI only.

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

A switch that does not clearly mean "on" now turns reporting off, so an
opt-out can never be read as consent:

- Environment: TRACE_USAGE_REPORTING set to anything but blank or a clear
  "on" (true/on/yes/1) disables; DO_NOT_TRACK set to anything but blank or
  a clear "no" (0/false/off/no) disables. Before, only a fixed list of
  values disabled, so TRACE_USAGE_REPORTING=disabled or DO_NOT_TRACK=on
  left reporting on.
- An environment that cannot be read (e.g. a SecurityException in a
  sandbox) now disables; it used to leave reporting on.
- New TraceClient.AllowsReporting(object) for a program's own setting:
  only true, or a string true/on/yes/1, allows reporting; anything else,
  including null, a number or a quoted "false", turns it off. The README
  and doc-comment examples now pass the setting through it.

Counterpart of Stephenson-Software/trace-client-java#51.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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