From 06de0a7636103dd2498465fceac7c6f8b055a561 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 5 Mar 2023 02:08:03 +0200 Subject: [PATCH] mask machine logs --- src/features/machines/components/Machine.js | 4 ++-- src/providers/SensitiveInfoProvider.js | 8 +++++++- src/utils/obfuscateStrings.js | 8 ++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/features/machines/components/Machine.js b/src/features/machines/components/Machine.js index 3554875..18910ab 100644 --- a/src/features/machines/components/Machine.js +++ b/src/features/machines/components/Machine.js @@ -63,7 +63,7 @@ const Machine = ({ }) => { const [open, setOpen] = React.useState(false); const classes = useRowStyles(); - const { mask } = useSensitiveInfo(); + const { mask, maskElements } = useSensitiveInfo(); const topActions = useMemo( () => actions.filter(a => a.top === true), @@ -122,7 +122,7 @@ const Machine = ({ - + diff --git a/src/providers/SensitiveInfoProvider.js b/src/providers/SensitiveInfoProvider.js index 1e97525..df378f4 100644 --- a/src/providers/SensitiveInfoProvider.js +++ b/src/providers/SensitiveInfoProvider.js @@ -37,7 +37,13 @@ const useSensitiveInfo = () => { return obfuscate(text, "#"); }; - return { enabled, onSensitiveInfoEnabled, mask }; + const maskElements = list => { + if (!enabled) return list; + const maskedList = list.map(z => obfuscate(z, "#")); + return maskedList; + }; + + return { enabled, onSensitiveInfoEnabled, mask, maskElements }; }; const SensitiveInfoProvider = ({ children }) => { diff --git a/src/utils/obfuscateStrings.js b/src/utils/obfuscateStrings.js index dc2d229..5c55cef 100644 --- a/src/utils/obfuscateStrings.js +++ b/src/utils/obfuscateStrings.js @@ -9,16 +9,16 @@ const obfuscateForChars = (text, placeholder = "*") => { const obfuscate = (text, placeholder = "*") => { if (text.length <= 2) return text; - if (text.length <= 4) { + if (text.length <= 5) { return obfuscateForChars(text); } const firstTwoChars = text.substring(0, 2); - const lastTwoChars = text.substring(text.length - 2); + const lastChar = text.substring(text.length - 1); const middleChars = text - .substring(2, text.length - 2) + .substring(2, text.length - 1) .replace(/[a-zA-Z0-9]/g, placeholder); - return firstTwoChars + middleChars + lastTwoChars; + return firstTwoChars + middleChars + lastChar; }; export { obfuscate };