Fix five remaining bugs from security review#265
Merged
joshuahannan merged 2 commits intomasterfrom Mar 12, 2026
Merged
Conversation
turbolent
approved these changes
Mar 11, 2026
Comment on lines
+290
to
+292
| panic("ExampleNFT.createEmptyCollection: The requested nftType <" | ||
| .concat(nftType.identifier) | ||
| .concat("> is not supported by this contract. Only ExampleNFT.NFT tokens are supported.")) |
Member
There was a problem hiding this comment.
Maybe use string interpolation here
Contributor
Author
There was a problem hiding this comment.
I'm planning on making another PR to update all the strings to use interpolation. 👍
1. setup_account_from_address.cdc: add early-return guard before storage.save so the transaction is idempotent. Without this it panicked when called on an account that already had a collection. Also adds unpublish before publish and the BorrowValue entitlement. 2. NFTForwarding.cdc: remove redundant `?? nil` from borrowRecipientCollection — Capability.borrow() already returns an optional, making the nil-coalescing a no-op. 3. ExampleNFT.cdc: add explicit type guard to createEmptyCollection so callers passing an unsupported nftType get a clear panic message instead of silently receiving an ExampleNFT.Collection. 4. ExampleNFT.cdc: comment out the emitNFTUpdated call in deposit that was marked "testing only". Leaves the code as a commented example so the pattern is visible but inactive by default. 5. MaliciousNFT.cdc: add an explicit comment explaining the intentional path/type collision in NFTCollectionData so it is clear to readers what vulnerability class the contract demonstrates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71d2a28 to
d4d8797
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setup_account_from_address.cdc— Added early-return guard beforestorage.saveso the transaction is idempotent (previously panicked if called on an account that already had a collection). Also addsunpublishbeforepublishand the missingBorrowValueentitlement.NFTForwarding.cdc— Removed redundant?? nilfromborrowRecipientCollection;Capability.borrow()already returns an optional, making the nil-coalescing a dead no-op.ExampleNFT.cdc— Added explicit type guard tocreateEmptyCollectionso callers passing an unsupportednftTypeget a clear panic message instead of silently receiving anExampleNFT.Collection.ExampleNFT.cdc— Commented out theemitNFTUpdatedblock indepositthat was already marked "testing only". The code is preserved as a commented example so the pattern is still visible.MaliciousNFT.cdc— Added a clear comment to the intentional path/type collision inresolveContractViewexplaining which vulnerability class the contract is meant to demonstrate.Test plan
testSetupAccountFromAddressIsIdempotent— callssetup_account_from_address.cdctwice on the same account and verifies it succeeds both timestestCreateEmptyCollectionRejectsWrongType— verifiescreateEmptyCollectionpanics with a descriptive message when passed an unsupported typemake ci)🤖 Generated with Claude Code