Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ gem "memoist", "~> 0.16.2"

gem "awesome_print", "~> 1.9"

gem 'facet_rails_common', git: 'https://github.com/0xfacet/facet_rails_common.git'

gem "redis", "~> 5.0"

Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ GIT
rbsecp256k1 (~> 6.0)
scrypt (~> 3.0)

GIT
remote: https://github.com/0xfacet/facet_rails_common.git
revision: 2d5cf107df9ea12bb7ab59a8b1ce4d38b4de483b
specs:
facet_rails_common (0.1.0)
order_query (~> 0.5.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -216,6 +223,9 @@ GEM
bigdecimal (>= 3.0)
ostruct (>= 0.2)
openssl (3.3.0)
order_query (0.5.5)
activerecord (>= 5.0, < 8.1)
activesupport (>= 5.0, < 8.1)
ostruct (0.6.3)
parallel (1.27.0)
parser (3.2.2.4)
Expand Down Expand Up @@ -406,6 +416,7 @@ DEPENDENCIES
debug
dotenv-rails (~> 2.8)
eth!
facet_rails_common!
fastlz (~> 0.1.0)
httparty (~> 0.22.0)
jwt (~> 2.8)
Expand Down
7 changes: 6 additions & 1 deletion app/models/collections_params_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def extract(content_uri)
begin
# Parse JSON (preserves key order)
# Use DataUri to correctly handle optional parameters like ESIP6
json_str = DataUri.new(content_uri).decoded_data
json_str = if content_uri.start_with?("data:,{")
content_uri.sub(/\Adata:,/, '')
else
DataUri.new(content_uri).decoded_data
end

# TODO: make sure this is safe
data = JSON.parse(json_str)

Expand Down
9 changes: 7 additions & 2 deletions app/models/generic_protocol_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def extract(content_uri)
return DEFAULT_PARAMS unless valid_data_uri?(content_uri)
begin
# Extract JSON from data URI using DataUri to support optional params (e.g., ESIP6)
json_str = DataUri.new(content_uri).decoded_data

json_str = if content_uri.start_with?("data:,{")
content_uri.sub(/\Adata:,/, '')
else
DataUri.new(content_uri).decoded_data
end
# Parse with security checks
data = parse_json_safely(json_str)

Expand Down Expand Up @@ -57,6 +60,8 @@ def valid_data_uri?(uri)
return false unless uri.is_a?(String)
return false unless DataUri.valid?(uri)

return true if uri.start_with?("data:,{")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Data URI Validation Order Issue

In valid_data_uri?, the DataUri.valid?(uri) check occurs before the special case for data:,{...} URIs. This order means URIs intended for the special handling will likely fail the initial DataUri.valid? check, preventing the dedicated extraction logic from being reached.

Fix in Cursor Fix in Web

# Ensure the payload is JSON (starts with '{')
begin
payload = DataUri.new(uri).decoded_data
Expand Down
93 changes: 0 additions & 93 deletions lib/data_uri.rb

This file was deleted.