File tree Expand file tree Collapse file tree 4 files changed +13
-17
lines changed Expand file tree Collapse file tree 4 files changed +13
-17
lines changed Original file line number Diff line number Diff line change 7
7
from , stringify ,
8
8
createElement ,
9
9
appendChild ,
10
+ replaceChildren ,
10
11
textContentSet ,
11
12
} from './native.mjs' ;
12
13
import { distraction , unselectable } from './element.mjs' ;
@@ -18,9 +19,12 @@ export function LavaDome(host, opts) {
18
19
// make exported API tamper-proof
19
20
defineProperties ( this , { text : { value : text } } ) ;
20
21
22
+ // get/create shadow for host (empty shadow content if there's any already)
23
+ const shadow = getShadow ( host , opts ) ;
24
+ replaceChildren ( shadow ) ;
25
+
21
26
// child of the shadow, where the secret is set, must be unselectable
22
27
const child = unselectable ( ) ;
23
- const shadow = getShadow ( host , opts ) ;
24
28
appendChild ( shadow , child ) ;
25
29
26
30
function text ( text ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const randomUUID = crypto?.randomUUID?.bind(crypto);
20
20
const n = ( obj , prop , accessor ) =>
21
21
obj && Function . prototype . call . bind ( getOwnPropertyDescriptor ( obj , prop ) [ accessor ] ) ;
22
22
23
+ export const replaceChildren = n ( globalThis ?. DocumentFragment ?. prototype , 'replaceChildren' , 'value' ) ;
23
24
export const attachShadow = n ( globalThis ?. Element ?. prototype , 'attachShadow' , 'value' ) ;
24
25
export const createElement = n ( globalThis ?. Document ?. prototype , 'createElement' , 'value' ) ;
25
26
export const appendChild = n ( globalThis ?. Node ?. prototype , 'appendChild' , 'value' ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ export default function App() {
22
22
< p id = "PRIVATE" >
23
23
< LavaDomeReact
24
24
unsafeOpenModeShadow = { unsafeOpenModeShadow }
25
- text = { toLavaDomeToken ( ' SECRET_CONTENT_ONLY_ACCESSIBLE_TO_LAVADOME' ) }
25
+ text = { toLavaDomeToken ( ` SECRET_CONTENT_ONLY_ACCESSIBLE_TO_LAVADOME: " ${ count } "` ) }
26
26
/>
27
27
</ p >
28
28
</ div >
Original file line number Diff line number Diff line change @@ -18,23 +18,14 @@ export const LavaDome = ({ text, unsafeOpenModeShadow }) => {
18
18
} ;
19
19
20
20
function LavaDomeShadow ( { host, token, unsafeOpenModeShadow } ) {
21
- let lavadome ;
22
-
23
- // exchange token for sensitive text before check
24
- const text = tokenToText ( token , unsafeOpenModeShadow ) ;
25
-
26
- // generate a lavadome instance reference with a teardown
27
- useEffect ( ( ) => {
28
- const opts = { unsafeOpenModeShadow } ;
29
- lavadome = new LavaDomeCore ( host . current , opts ) ;
30
- return ( ) => lavadome = null ;
31
- } , [ ] ) ;
32
-
33
- // use a unique and useless representation of the token as the useEffect dep
34
- const dep = tokenToDep ( token ) ;
21
+ const
22
+ // exchange token for sensitive text before check
23
+ text = tokenToText ( token , unsafeOpenModeShadow ) ,
24
+ // use a unique and useless representation of the token as the useEffect dep
25
+ dep = tokenToDep ( token ) ;
35
26
36
27
// update lavadome secret text (given that the token is updated too)
37
- useEffect ( ( ) => lavadome . text ( text ) , [ dep ] ) ;
28
+ useEffect ( ( ) => new LavaDomeCore ( host . current , { unsafeOpenModeShadow } ) . text ( text ) , [ dep ] ) ;
38
29
39
30
return < > </ > ;
40
31
}
You can’t perform that action at this time.
0 commit comments