From 63a49eba0a60835fc81476eb03f892f7e42dca0b Mon Sep 17 00:00:00 2001 From: lserra-iov Date: Tue, 17 Sep 2024 15:51:19 -0300 Subject: [PATCH] Validate sitekey --- src/common/services/FlyoverService.ts | 5 +++-- src/common/utils/utils.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/services/FlyoverService.ts b/src/common/services/FlyoverService.ts index 320e1eef..091c47e5 100644 --- a/src/common/services/FlyoverService.ts +++ b/src/common/services/FlyoverService.ts @@ -11,7 +11,7 @@ import { } from '@/common/types'; import { providers } from 'ethers'; import { EnvironmentAccessorService } from './enviroment-accessor.service'; -import { ServiceError } from '../utils'; +import { isValidSiteKey, ServiceError } from '../utils'; export default class FlyoverService { flyover?: Flyover; @@ -108,7 +108,8 @@ export default class FlyoverService { minTransactionValue: new WeiBig(provider.pegout.minTransactionValue, 'wei'), }, })); - this.siteKey = liquidityProviders[0].siteKey; + const providerKey = liquidityProviders[0].siteKey; + if (isValidSiteKey(providerKey)) this.siteKey = liquidityProviders[0].siteKey; resolve(providers2wp); }) .catch((error: Error) => { diff --git a/src/common/utils/utils.ts b/src/common/utils/utils.ts index c8f4e0de..cccd51d6 100644 --- a/src/common/utils/utils.ts +++ b/src/common/utils/utils.ts @@ -375,7 +375,15 @@ export function copyToClipboard(value: string) { navigator.clipboard.writeText(value); } +export function isValidSiteKey(siteKey: string): boolean { + const siteKeyPattern = /^[A-Za-z0-9_-]+$/; + return siteKeyPattern.test(siteKey); +} + export function appendRecaptcha(siteKey: string): void { + if (!isValidSiteKey(siteKey)) { + return; + } const scriptTag = document.createElement('script'); scriptTag.type = 'text/javascript'; scriptTag.async = true;