Skip to content

Check symbol-keyed properties in Match object patterns - #6947

Open
fubhy wants to merge 1 commit into
mainfrom
audit/repro-core-match-symbol-pattern
Open

Check symbol-keyed properties in Match object patterns#6947
fubhy wants to merge 1 commit into
mainfrom
audit/repro-core-match-symbol-pattern

Conversation

@fubhy

@fubhy fubhy commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

A valid typed object pattern whose only key is a symbol compiles as an empty conjunction and matches non-null objects that do not satisfy the symbol property's constraint.

Important

This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.

Symbol-keyed object patterns match without checking the symbol

Module: Match
Audit ID: core-g-r-match-symbol-key-pattern-omitted
Severity / confidence: medium / high

What happens

A valid typed object pattern whose only key is a symbol compiles as an empty conjunction and matches non-null objects that do not satisfy the symbol property's constraint.

Why it happens

The runtime compiler enumerates pattern properties with Object.entries, which omits symbols. A symbol-only pattern therefore has no compiled predicates and accepts the wrong value.

Expected behavior

Types.PatternBase maps every key of a record-shaped value, including symbol keys, and a successful object-pattern match satisfies every supplied property constraint.

Relevant implementation

These links and excerpts are pinned to audit base c9b56ab507f224426ee8388dc450da447ec4715f.

View problematic code at packages/effect/src/Match.ts:2234-2238
  export type PatternBase<A> = A extends ReadonlyArray<infer _T> ? ReadonlyArray<any> | PatternPrimitive<A>
    : A extends Record<string, any> ? Partial<
        { [K in keyof A]: PatternPrimitive<A[K] & {}> | PatternBase<A[K] & {}> }
      >
    : never

View exact lines on GitHub

View problematic code at packages/effect/src/internal/matcher.ts:126-145
  } else if (pattern !== null && typeof pattern === "object") {
    const keysAndPredicates = Object.entries(pattern).map(
      ([k, p]) => [k, makePredicate(p)] as const
    )
    const len = keysAndPredicates.length

    return (u: unknown) => {
      if (typeof u !== "object" || u === null) {
        return false
      }

      for (let i = 0; i < len; i++) {
        const [key, predicate] = keysAndPredicates[i]
        if (!(key in u) || predicate((u as any)[key]) === false) {
          return false
        }
      }

      return true
    }

View exact lines on GitHub

Reproduction

pnpm vitest run packages/effect/test/Match.test.ts -t "checks symbol-keyed object pattern properties"

Observed failure: The intended failure was reproduced: the matcher returned "hit" instead of "miss".

Implementation handoff

The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.

  1. Start with the pinned implementation excerpts and the Why it happens analysis above.
  2. Change the implementation so it satisfies the stated Expected behavior; do not weaken or remove the reproduction assertions.
  3. Run the focused reproduction command(s) and confirm the observed failures become passing tests:
pnpm vitest run packages/effect/test/Match.test.ts -t "checks symbol-keyed object pattern properties"
  1. Run the affected package's existing tests, then the repository lint and type checks before requesting review.

Audit provenance

  • Audit base: c9b56ab507f224426ee8388dc450da447ec4715f
  • Reproduction base: c9b56ab507f224426ee8388dc450da447ec4715f
  • Findings: core-g-r-match-symbol-key-pattern-omitted
  • Initial patch: focused reproduction tests; implementation fix pending

@fubhy fubhy added the audit Findings originating from the Effect runtime correctness audit label Aug 4, 2026
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Aug 4, 2026
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 20bb27d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Aug 4, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

This PR reproduces the symbol-keyed object pattern bug with a focused regression test, but the implementation fix in packages/effect/src/internal/matcher.ts is still missing. CI will continue to fail until the fix is included.

Reviewed changes

  • packages/effect/test/Match.test.ts: adds a regression test demonstrating that an object pattern with only a symbol key wrongly matches a value where the symbol property does not satisfy the constraint.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔Fix 👍s ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Match.orElse(() => "miss")
)

strictEqual(match({ [key]: "other" }), "miss")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test only exercises the wrong-value path. Consider also asserting that { [key]: "expected" } matches ("hit") and that {} returns "miss", matching the hit/miss coverage of the neighboring tests and reducing the chance that an incomplete fix passes accidentally.

@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 audit Findings originating from the Effect runtime correctness audit bug Something isn't working

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

1 participant