Skip to content

fix(api): require CID ownership to unpin IPFS content (IDOR) - #1172

Merged
Ejirowebfi merged 7 commits into
Favourorg:mainfrom
Dennis-Ritchie1:fix/1155-ipfs-unpin-idor
Aug 25, 2026
Merged

fix(api): require CID ownership to unpin IPFS content (IDOR)#1172
Ejirowebfi merged 7 commits into
Favourorg:mainfrom
Dennis-Ritchie1:fix/1155-ipfs-unpin-idor

Conversation

@Dennis-Ritchie1

@Dennis-Ritchie1 Dennis-Ritchie1 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • POST /api/ipfs/unpin previously authorized any request that presented a valid JWT — since a fresh JWT is free to obtain (no on-chain history required), any wallet could unpin any other user's IPFS metadata by CID.
  • Adds a pin-ownership registry (api/_lib/pinOwnership.ts) populated at upload time by upload-json.ts / upload-file.ts, and a new api/ipfs/unpin.ts endpoint that resolves a CID back to the wallet that pinned it before calling Pinata.
  • A CID with no ownership record on file is denied by default (never allow-by-default for unindexed content), matching the acceptance criteria in Any authenticated wallet can unpin any user's IPFS metadata (IDOR) #1155.
  • Every unpin attempt — allowed or rejected — is audit-logged with address, cid, and outcome.
  • Documented the new control in SECURITY.md under "Known security considerations".
  • Unrelated blocker fix bundled in: frontend/package.json had react bumped to 19.2.8 (chore(deps): bump react from 19.2.7 to 19.2.8 in /frontend #1049) without react-dom, which hard-errors at runtime and broke the entire frontend test suite / this repo's pre-push hook. Aligned react-dom to 19.2.8 so the branch could be pushed through the hook cleanly.

Test plan

  • npx vitest run api/ipfs/unpin.test.ts — 6/6 passing: owner unpins own CID (allow), non-owner denied (403), unindexed CID denied by default (403), malformed cid rejected (400), missing JWT rejected (401), non-POST rejected (405)
  • npm test -- --run in frontend/ — 609/609 passing after the react-dom fix

Closes #1155

Dennis-Ritchie1 and others added 7 commits August 25, 2026 09:21
POST /api/ipfs/unpin previously authorized any wallet with a valid JWT to
unpin any CID, since a fresh JWT costs nothing (challenge/response needs no
on-chain history) and the wallet address was never checked against who
actually pinned the content.

Add a pin-ownership registry (api/_lib/pinOwnership.ts) populated by
upload-json.ts / upload-file.ts at pin time, and a new unpin.ts endpoint
that resolves a CID back to its pinning wallet before calling Pinata. A CID
with no ownership record is denied by default rather than allowed, and
every attempt (allowed or rejected) is audit-logged with address, cid, and
outcome.

Closes Favourorg#1155
PR Favourorg#1049 bumped react to 19.2.8 but left react-dom pinned to 19.2.7,
which React now hard-errors on at runtime ("Incompatible React versions"),
breaking the entire frontend test suite and blocking the pre-push hook.
…-idor

# Conflicts:
#	api/ipfs/unpin.test.ts
#	api/ipfs/unpin.ts
#	api/ipfs/upload-file.ts
#	api/ipfs/upload-json.ts
#	frontend/package-lock.json
#	frontend/package.json
…on merge

The two-step admin-rotation change landed with a contract that does not
compile, so Contract Build, Contract Tests and Rust Formatting all fail on
this branch's merge of main.

- `BatchSizeExceeded`, `NoPendingProposal` and `ProposalExpired` were all
  assigned discriminant 24 (E0081). Renumber them 25/26/27 and update the
  error tables in docs/contract-abi.md and README.md.
- `test.rs` called `Ledger::with_mut` without importing the trait (E0599).
- Apply `cargo fmt`.

Two test failures the compile error had been masking:

- `migrate`: the v3 `TokenInfo` walk is chunked and may still be mid-flight,
  but the new v4 step ran unconditionally and pushed the version marker to 4.
  Every later `migrate` call then skipped the v3 block, stranding the entries
  beyond the cursor in instance storage — exactly what the v3 chunking comment
  warns against. Return early while v3 is incomplete.
- `accept_admin` cleared an expired proposal and then returned
  `ProposalExpired`; the error reverts the invocation, so the write never
  persisted. Drop the dead write and state the real behaviour: an expired
  proposal stays on record but is inert, and the admin cancels or re-proposes.
  Docs and the test now assert that.

Regenerate the test snapshots, which were stale from the same merge.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFDD5GssS1ik3KcH3XMx43
`Contract/Frontend Drift` fails because `CONTRACT_TOPIC_MAP` still carries the
retired single-step `adm_upd` topic and is missing `fee_redir`. The contract
now emits `adm_prop`, `adm_acc` and `adm_can` for a rotation, so every admin
event was being dropped from Transaction History and CSV exports.

Map all four topics, decode their payloads (including `adm_prop`'s expiry
ledger and `fee_redir`'s skipped recipient and amount), and update the
regression tests with real XDR fixtures for each.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFDD5GssS1ik3KcH3XMx43
`check-access-control-docs-drift.sh` stripped `//` comments with a naive
regex, so `if &buf[..7] != b"ipfs://" {` lost its opening brace and the brace
counter closed `set_metadata` forty lines early. The truncated body hid the
`creator != admin` guard, and the check exited 1 — failing the workflow.

Strip line comments with a scanner that skips string literals, add a rule for
the stored-creator identity check, and correct `set_metadata`'s expected
claims: it authorizes its caller and compares them against the token's stored
creator, and factory-admin privilege grants nothing there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HFDD5GssS1ik3KcH3XMx43
`cargo clippy -- -D warnings` failed on `collapsible_if` in the fee
distribution loop. Collapsing into `share > 0 && ...is_err()` keeps the
short-circuit semantics: the transfer is still only attempted for a
non-zero share.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019E8cJSSGUUPiea6LFYL8wN
@Ejirowebfi
Ejirowebfi merged commit 70fd048 into Favourorg:main Aug 25, 2026
20 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 25, 2026
## [1.8.3](v1.8.2...v1.8.3) (2026-08-25)

### Bug Fixes

* **api:** require CID ownership to unpin IPFS content (IDOR) ([#1172](#1172)) ([70fd048](70fd048)), closes [#1155](#1155) [#1049](#1049)
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.8.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any authenticated wallet can unpin any user's IPFS metadata (IDOR)

2 participants