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

fix: Make QR scanner more strict #28521

Merged
merged 1 commit into from
Nov 18, 2024
Merged
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
16 changes: 13 additions & 3 deletions ui/components/app/modals/qr-scanner/qr-scanner.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const READY_STATE = {
READY: 'READY',
};

const ethereumPrefix = 'ethereum:';
// A 0x-prefixed Ethereum address is 42 characters (2 prefix + 40 address)
const addressLength = 42;

const parseContent = (content) => {
let type = 'unknown';
let values = {};
Expand All @@ -31,12 +35,18 @@ const parseContent = (content) => {
// For ex. EIP-681 (https://eips.ethereum.org/EIPS/eip-681)

// Ethereum address links - fox ex. ethereum:0x.....1111
if (content.split('ethereum:').length > 1) {
if (
content.split(ethereumPrefix).length > 1 &&
content.length === ethereumPrefix.length + addressLength
) {
type = 'address';
// uses regex capture groups to match and extract address while ignoring everything else
// uses regex capture groups to match and extract address
values = { address: parseScanContent(content) };
// Regular ethereum addresses - fox ex. 0x.....1111
} else if (content.substring(0, 2).toLowerCase() === '0x') {
} else if (
content.substring(0, 2).toLowerCase() === '0x' &&
content.length === addressLength
) {
type = 'address';
values = { address: content };
}
Expand Down