Skip to content

Commit

Permalink
fix(sanitizer): remove lib and add regex (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
duspada authored Feb 22, 2023
1 parent ae2f609 commit 26e630e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 395 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/helpers",
"version": "0.7.1",
"version": "0.7.2",
"description": "Builders helpers library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -92,8 +92,5 @@
"ts-jest": "29.0.3",
"typescript": "4.9.3",
"uglify-js": "3.17.4"
},
"dependencies": {
"isomorphic-dompurify": "^1.0.0"
}
}
27 changes: 4 additions & 23 deletions src/shared/sanitizer.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import * as DOMPurify from 'isomorphic-dompurify';

type ConfigSanitize = DOMPurify.Config & {
RETURN_DOM_FRAGMENT?: false | undefined;
RETURN_DOM?: false | undefined;
};

const defaultConfig: ConfigSanitize = {
RETURN_DOM_FRAGMENT: false,
SANITIZE_DOM: true,
USE_PROFILES: { html: false },
};

export const sanitizeValues = <T = Record<string, any>>(
values: T,
config?: ConfigSanitize,
): T => {
const purifiedValues = DOMPurify.sanitize(JSON.stringify(values), {
...defaultConfig,
...config,
});

return JSON.parse(purifiedValues);
export const sanitizeValues = <T = Record<string, any>>(values: T): T => {
if (!values) return {} as T;
const strippedString = JSON.stringify(values).replace(/<\/?[^>]+(>|$)/g, '');
return JSON.parse(strippedString);
};

export const isSecureLink = (url: string): boolean => {
Expand Down
Loading

0 comments on commit 26e630e

Please sign in to comment.