Skip to content

Commit 01208af

Browse files
committed
chore: use shadow dom to hide sensitive email/name from extensions
1 parent 589d554 commit 01208af

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/services/html/profile-popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{{initials}}
66
</div>
77
<div class="user-info">
8-
<div class="user-name">{{userName}}</div>
9-
<div class="user-email">{{email}}</div>
8+
<div class="user-name"><secure-name></secure-name></div>
9+
<div class="user-email"><secure-email></secure-email></div>
1010
<div class="{{planClass}}">{{planName}}</div>
1111
</div>
1212
</div>

src/services/profile-menu.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ define(function (require, exports, module) {
179179
_setupDocumentClickHandler();
180180
}
181181

182+
let userEmail="";
183+
class SecureEmail extends HTMLElement {
184+
constructor() {
185+
super();
186+
// Create closed shadow root - this is for security that extensions wont be able to read email from DOM
187+
const shadow = this.attachShadow({ mode: 'closed' });
188+
// Create the email display with some obfuscation techniques
189+
shadow.innerHTML = `<span>${userEmail}</span>`;
190+
}
191+
}
192+
// Register the custom element
193+
customElements.define('secure-email', SecureEmail);
194+
let userName="";
195+
class SecureName extends HTMLElement {
196+
constructor() {
197+
super();
198+
// Create closed shadow root - this is for security that extensions wont be able to read name from DOM
199+
const shadow = this.attachShadow({ mode: 'closed' });
200+
// Create the email display with some obfuscation techniques
201+
shadow.innerHTML = `<span>${userName}</span>`;
202+
}
203+
}
204+
// Register the custom element
205+
customElements.define('secure-name', SecureName);
206+
182207
/**
183208
* Shows the user profile popup when the user is logged in
184209
*/
@@ -189,12 +214,12 @@ define(function (require, exports, module) {
189214
return;
190215
}
191216
const profileData = KernalModeTrust.loginService.getProfile();
217+
userEmail = profileData.email;
218+
userName = profileData.firstName + " " + profileData.lastName;
192219
const templateData = {
193220
initials: profileData.profileIcon.initials,
194221
avatarColor: profileData.profileIcon.color,
195-
userName: profileData.firstName + " " + profileData.lastName,
196-
email: profileData.email,
197-
planClass: "user-plan-free",
222+
planClass: "user-plan-free", // "user-plan-paid" for paid plan
198223
planName: "Free Plan",
199224
quotaUsed: "7,000",
200225
quotaTotal: "10,000",

0 commit comments

Comments
 (0)