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 code scanning alert #2: DOM text reinterpreted as HTML #17

Merged
merged 1 commit into from
Sep 19, 2024
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
12 changes: 7 additions & 5 deletions ui/components/blockexplorer/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRouter } from "next/router";
import { ethers } from "ethers";
import { localhost } from "wagmi/chains";
import { getLocalProvider } from "~~/utils/scaffold-eth";
import DOMPurify from "dompurify";

const provider = getLocalProvider(localhost);
export const SearchBar = () => {
Expand All @@ -11,20 +12,21 @@ export const SearchBar = () => {

const handleSearch = async (event: React.FormEvent) => {
event.preventDefault();
if (ethers.utils.isHexString(searchInput)) {
const sanitizedInput = DOMPurify.sanitize(searchInput);
if (ethers.utils.isHexString(sanitizedInput)) {
try {
const tx = await provider?.getTransaction(searchInput);
const tx = await provider?.getTransaction(sanitizedInput);
if (tx) {
router.push(`/blockexplorer/transaction/${searchInput}`);
router.push(`/blockexplorer/transaction/${sanitizedInput}`);
return;
}
} catch (error) {
console.error("Failed to fetch transaction:", error);
}
}

if (ethers.utils.isAddress(searchInput)) {
router.push(`/blockexplorer/address/${searchInput}`);
if (ethers.utils.isAddress(sanitizedInput)) {
router.push(`/blockexplorer/address/${sanitizedInput}`);
return;
}
};
Expand Down
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"use-debounce": "10.0.3",
"usehooks-ts": "3.1.0",
"wagmi": "2.12.12",
"zustand": "^4.5.5"
"zustand": "^4.5.5",
"dompurify": "^3.1.6"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand Down
Loading