Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify NFT content media type before pinning #17392

Merged
merged 2 commits into from
Mar 6, 2023
Merged

Verify NFT content media type before pinning #17392

merged 2 commits into from
Mar 6, 2023

Conversation

cypt4
Copy link
Collaborator

@cypt4 cypt4 commented Feb 27, 2023

Resolves brave/brave-browser#28775

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

After an NFT added to the wallet, media type of the "image" field is checked. So if it differs from "image/.." NFT won't be pinned. Probably we can test this by sniffing NFT gateway for the https://nftstorage.link(example)/ipfs/IMAGE_CID request by changing content_type here from image/png to blablabla

@cypt4 cypt4 requested a review from a team as a code owner February 27, 2023 15:26
@@ -222,7 +222,8 @@ enum WalletPinServiceErrorCode {
ERR_WRONG_METADATA_FORMAT = 4,
ERR_ALREADY_PINNED = 5,
ERR_NOT_PINNED = 6,
ERR_PINNING_FAILED = 7
ERR_PINNING_FAILED = 7,
ERR_MEDIA_TYPE_UNSUPORTED = 8
Copy link
Collaborator

Choose a reason for hiding this comment

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

UNSUPORTED ->
UNSUPPORTED

@@ -149,11 +152,94 @@ std::string BraveWalletPinService::ErrorCodeToString(
return "ERR_NOT_PINNED";
case mojom::WalletPinServiceErrorCode::ERR_PINNING_FAILED:
return "ERR_PINNING_FAILED";
case mojom::WalletPinServiceErrorCode::ERR_MEDIA_TYPE_UNSUPORTED:
return "ERR_MEDIA_TYPE_UNSUPORTED";
Copy link
Collaborator

Choose a reason for hiding this comment

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

UNSUPPORTED

Comment on lines 603 to 611
content_type_checker_->CheckContentTypeSupported(
*image_url,
base::BindOnce(&BraveWalletPinService::OnContentTypeChecked,
weak_ptr_factory_.GetWeakPtr(), std::move(service),
std::move(token), std::move(cids),
std::move(callback)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs S&P review as we are getting arbitrary url resource from blockchain and forcing browser to make a request to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a bit different : actually we make a call to the IPFS gateway which we use to fetch metadata on the previous step. Final url looks like https://ipfs.io/CID/...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine. It's not arbitrary, like @cypt4 said and we only call IPFS gateway. This code also doesn't fetch a file, only response headers.


raw_ptr<PrefService> pref_service_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// Reports that are actively being sent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What reports?

Copy link
Collaborator

@supermassive supermassive left a comment

Choose a reason for hiding this comment

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

👍

@srirambv
Copy link
Contributor

Verification passed on

Brave 1.51.32 Chromium: 111.0.5563.64 (Official Build) nightly (32-bit)
Revision c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995}
OS Windows 11 Version 22H2 (Build 23403.1001)
  • Verified steps from PR
  • Verified when content-type is not image/png NFT Pinning fails
    image

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

Successfully merging this pull request may close these issues.

Verify media type before pinning an NFT
4 participants