Skip to content

Commit

Permalink
fix(dashboard): sanitize href input in text widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjagad committed Aug 6, 2024
1 parent 982b23f commit 6c2bd5f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@types/papaparse": "^5.3.10",
"@types/react": "^18.2.12",
"@types/react-dom": "^18.2.5",
"@types/validator": "^13.12.0",
"css-loader": "6.8.1",
"dotenv": "^16.3.1",
"eslint-config-iot-app-kit": "10.10.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type { CSSProperties } from 'react';
import React from 'react';
import { defaultFontSettings } from '../styledText/defaultFontSettings';
import type { TextWidget } from '../../types';
import isValidUrl from 'is-url';
// import isValidUrl from 'is-url';
import DOMPurify from 'dompurify';
import { isURL } from 'validator';

type TextLinkProps = TextWidget;

Expand All @@ -23,7 +25,9 @@ const TextLink: React.FC<TextLinkProps> = (widget) => {
color: fontColor,
};

const renderedHref = href && isValidUrl(href) ? href : undefined;
const sanitizedHref = href ? DOMPurify.sanitize(href) : undefined;
const isValidUrl = sanitizedHref ? isURL(sanitizedHref) : false;
const renderedHref = isValidUrl ? sanitizedHref : undefined;

return (
<a href={renderedHref} className={className} style={style}>
Expand Down

0 comments on commit 6c2bd5f

Please sign in to comment.