Skip to content

fix(account): validate multisignature thresholds and weights before signing (#31) - #40

Open
aswadi wants to merge 1 commit into
HyperDevTools:mainfrom
aswadi:fix/validate-multisig-thresholds-weights-31
Open

aswadi wants to merge 1 commit into
HyperDevTools:mainfrom
aswadi:fix/validate-multisig-thresholds-weights-31

Conversation

@aswadi

@aswadi aswadi commented Nov 15, 2026

Copy link
Copy Markdown

Closes #31

Hardens AccountManager.signMultiSigTransaction (src/core/account.ts) so thresholds, signer secrets, and optional signer weight maps are validated upfront and transaction is never mutated when validation or threshold checks fail:

  • Strict integer range validation (src/core/account.ts):
    • Validates requiredThreshold as a finite integer in 1..255 (MIN_SIGNING_THRESHOLD..MAX_SIGNING_THRESHOLD), throwing ToolkitError (ERR_INVALID_THRESHOLD) on zero, negative, fractional, non-finite, or excessive values.
    • Validates signerWeights (when supplied) as a plain object whose entries are finite integers in 1..255 (MIN_SIGNER_WEIGHT..MAX_SIGNER_WEIGHT), throwing ValidationError on invalid entries.
  • Documented missing-weight policy & prototype-pollution guard:
    • When signerWeights is omitted, each unique signer contributes weight 1.
    • When signerWeights is provided, every participating signer must have an explicit own property (Object.prototype.hasOwnProperty.call); missing entries throw ValidationError instead of silently defaulting to 1 and inflating accumulated weight.
  • Public-key deduplication & atomic signing:
    • Resolves and deduplicates signerSecrets (including whitespace-trimmed duplicates) by Stellar public key so duplicate signers never contribute weight or signatures twice.
    • Verifies accumulatedWeight >= requiredThreshold (throwing ToolkitError with ERR_INSUFFICIENT_SIGNATURES when insufficient) before calling transaction.sign(kp), leaving transaction.signatures completely untouched on any failure.
  • Tests & API docs (src/__tests__/account.test.ts, docs/api/account-manager.md):
    • Adds security unit tests covering zero, negative, fractional, non-finite, excessive, duplicate, missing-weight, prototype-inherited weight, malformed secret, and insufficient-weight scenarios, and documents the validation & missing-weight contract in docs/api/account-manager.md.

Local Verification

  • npx prettier --check "src/**/*.ts" -> all matched files formatted cleanly
  • npm run lint -> 0 warnings, 0 errors
  • npm test -- --coverage --runInBand -> 7 suites passed (77 / 77 tests, 93.91% statement coverage)
  • npm run build && npx tsc --noEmit -> 0 errors
  • npm audit --audit-level=moderate -> 0 moderate/high/critical vulnerabilities

@aswadi
aswadi requested a review from Code-Kaybee as a code owner November 15, 2026 02:41

This branch has not been deployed

No deployments
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.

Validate multisignature thresholds and weights before signing

1 participant