Skip to content

harden: add optional owner validation to fetchSlab#192

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/fetchSlab-owner-validation
Open

harden: add optional owner validation to fetchSlab#192
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:harden/fetchSlab-owner-validation

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

@0x-SquidSol 0x-SquidSol commented Apr 13, 2026

Summary

  • fetchSlab returned raw account data without checking info.owner against the expected Percolator program ID
  • A malicious or misconfigured RPC could return data from an arbitrary account — if it has the correct magic bytes and matches a known slab size, the SDK would parse it as a valid slab with attacker-controlled engine state
  • getMarketsByAddress already has owner validation (PR fix(discovery): validate account owner in getMarketsByAddress #128), but fetchSlab (used directly by keepers and ADL bots) did not
  • Fix: Added optional expectedOwner?: PublicKey parameter. When provided, validates info.owner.equals(expectedOwner) before returning. Fully backward compatible.

Test plan

  • No new test failures (729 passed, same 16 pre-existing)
  • Verify fetchSlab(conn, key, wrongOwner) throws with descriptive owner mismatch error
  • Verify fetchSlab(conn, key) (no owner) still works as before

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Added optional ownership verification for enhanced data integrity. When enabled, the system now validates ownership and provides explicit error messages including expected versus actual ownership values, helping users quickly diagnose and resolve authentication issues.

fetchSlab returned raw account data without checking info.owner
against the expected Percolator program ID. A malicious RPC could
return crafted data from an arbitrary account, and the SDK would
parse it as a valid slab (magic + detectSlabLayout checks pass
for any account with correct magic and matching size).

Added optional expectedOwner parameter. When provided, validates
info.owner.equals(expectedOwner) before returning data. Backward
compatible — existing callers without the param are unaffected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

The fetchSlab function in src/solana/slab.ts was enhanced with an optional expectedOwner parameter that validates the fetched Solana account's owner matches the provided public key, throwing an explicit error with base58 values on mismatch.

Changes

Cohort / File(s) Summary
Owner Validation Enhancement
src/solana/slab.ts
Added optional expectedOwner parameter to fetchSlab() function with validation logic that compares account owner against expected value and throws descriptive error on mismatch.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A slab that fetches with care and grace,
Now checks that owners are in their place,
No sneaky mismatches shall ever pass,
With validation bright, at last, at last! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding optional owner validation to the fetchSlab function, which is the core purpose of this security-hardening PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/solana/slab.ts (1)

1602-1603: Consider adding a strict variant to avoid accidental non-validation at call sites.

Because validation is opt-in, callers can still unintentionally skip owner checks. A small follow-up (e.g., fetchSlabStrict(connection, slabPubkey, expectedOwner) wrapper) would make safer usage easier for keeper/ADL paths.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/solana/slab.ts` around lines 1602 - 1603, Add a strict wrapper that
enforces owner validation so callers can't accidentally skip it: create a new
function (e.g., fetchSlabStrict) that wraps the existing fetchSlab (or the
function taking slabPubkey and expectedOwner?) and requires expectedOwner to be
provided, performs the owner check, and throws an error if the slab owner is
missing or mismatches expectedOwner; update or document usages in keeper/ADL
paths to call fetchSlabStrict instead of the optional-validate variant to
guarantee validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/solana/slab.ts`:
- Around line 1602-1603: Add a strict wrapper that enforces owner validation so
callers can't accidentally skip it: create a new function (e.g.,
fetchSlabStrict) that wraps the existing fetchSlab (or the function taking
slabPubkey and expectedOwner?) and requires expectedOwner to be provided,
performs the owner check, and throws an error if the slab owner is missing or
mismatches expectedOwner; update or document usages in keeper/ADL paths to call
fetchSlabStrict instead of the optional-validate variant to guarantee
validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e94165d9-52c7-43c5-b464-d992c074b919

📥 Commits

Reviewing files that changed from the base of the PR and between 2f80d79 and 6d42fde.

📒 Files selected for processing (1)
  • src/solana/slab.ts

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