Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 7665b7c

Browse files
Improve masking for secret field (#108)
1 parent c5ee78c commit 7665b7c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cloudquery/plugin-config-ui-lib",
33
"description": "Plugin configuration UI library for CloudQuery Cloud App",
4-
"version": "11.3.0",
4+
"version": "11.3.1",
55
"private": false,
66
"main": "dist/index.cjs.js",
77
"module": "dist/index.esm.js",

src/components/inputs/secretInput/index.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ const getDefaultValue = (object: any, path: string) =>
1212
// eslint-disable-next-line unicorn/no-array-reduce
1313
path.split('.').reduce((a, b) => a[b], object);
1414

15+
function checkWebkitTextSecuritySupported() {
16+
const input = document.createElement('input');
17+
input.style.display = 'none';
18+
document.body.append(input);
19+
const style = window.getComputedStyle(input);
20+
21+
return !!(style as any).webkitTextSecurity;
22+
}
23+
24+
const isWebkitTextSecuritySupported = checkWebkitTextSecuritySupported();
25+
1526
/**
1627
* @public
1728
*/
@@ -77,6 +88,10 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
7788
const displayValue = isObscured ? obfuscateSecretDisplay(value) : value;
7889
const isBlurred = !showPlainText && !!value && !isObscured;
7990

91+
// The goal is to use webkitTextSecurity only if the browser supports it or if the field is multiline.
92+
// If the browser does not support webkitTextSecurity, we will use the password type.
93+
const useWebkitTextSecurity = isWebkitTextSecuritySupported || textFieldProps?.multiline;
94+
8095
return (
8196
<Stack
8297
direction="row"
@@ -90,7 +105,7 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
90105
fullWidth={true}
91106
helperText={helperText}
92107
label={label}
93-
autoComplete="off"
108+
autoComplete={useWebkitTextSecurity ? 'off' : 'one-time-code'}
94109
required={true}
95110
onChange={onChange}
96111
onBlur={onBlur}
@@ -101,11 +116,11 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
101116
...textFieldProps?.sx,
102117
input: {
103118
...(textFieldProps?.sx as any)?.input,
104-
filter: isBlurred ? 'blur(3px)' : undefined,
119+
WebkitTextSecurity: useWebkitTextSecurity && isBlurred ? 'disc' : undefined,
105120
},
106121
textarea: {
107122
...(textFieldProps?.sx as any)?.textarea,
108-
filter: isBlurred ? 'blur(3px)' : undefined,
123+
WebkitTextSecurity: useWebkitTextSecurity && isBlurred ? 'disc' : undefined,
109124
},
110125
}}
111126
ref={ref}
@@ -127,6 +142,9 @@ export const SecretInput = React.forwardRef<HTMLDivElement, SecretInputProps>(
127142
) : null,
128143
},
129144
}}
145+
type={
146+
!useWebkitTextSecurity && isBlurred && !textFieldProps?.multiline ? 'password' : 'text'
147+
}
130148
/>
131149
{isSecret && (
132150
<FormFieldReset

0 commit comments

Comments
 (0)