Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block external font-face set #49

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/src/element.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ function creator(style, tag, text = '') {

const invoker = creator => () => creator();

// an element that is hard to find/select
export const unselectable = invoker(creator({
// an element that it should be hard to find/select/leak from/etc
export const hardened = invoker(creator({
// decide on an unguessable font-family (non-existing) so an external one cannot be applied
'font-family': rand(20),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not go even higher than 20?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What number would be sufficient?

// makes element uneditable to prevent document.execCommand HTML injection attacks
'-webkit-user-modify': 'unset',
// makes element unselectable to prevent getSelection attacks
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/lavadome.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
replaceChildren,
textContentSet,
} from './native.mjs';
import {distraction, unselectable} from './element.mjs';
import {distraction, hardened} from './element.mjs';
import {getShadow} from './shadow.mjs';

export function LavaDome(host, opts) {
Expand All @@ -23,8 +23,8 @@ export function LavaDome(host, opts) {
const shadow = getShadow(host, opts);
replaceChildren(shadow);

// child of the shadow, where the secret is set, must be unselectable
const child = unselectable();
// child of the shadow, where the secret is set, must be hardened
const child = hardened();
appendChild(shadow, child);

function text(text) {
Expand Down