Skip to content

Commit b19128d

Browse files
authored
Development (#229)
* address security issues * update dependencies
1 parent 8018b97 commit b19128d

File tree

5 files changed

+96
-106
lines changed

5 files changed

+96
-106
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313
"main": "index.js",
1414
"dependencies": {
15-
"@babel/helper-validator-identifier": "^7.24.6",
15+
"@babel/helper-validator-identifier": "^7.27.1",
1616
"@types/node": "^24.0.14",
17-
"dotenv": "^17.2.0",
17+
"dotenv": "^17.2.1",
1818

1919
"typescript": "^5.8.3",
2020
"workbox-build": "^7.3.0"

src/api.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2018 Gnock
33
* Copyright (c) 2018-2019 The Masari Project
44
* Copyright (c) 2018-2020 The Karbo developers
5-
* Copyright (c) 2018-2023 Conceal Community, Conceal.Network & Conceal Devs
5+
* Copyright (c) 2018-2025 Conceal Community, Conceal.Network & Conceal Devs
66
*
77
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
88
*
@@ -17,15 +17,38 @@
1717

1818
import {WalletRepository} from "./model/WalletRepository";
1919

20+
// List of allowed parent origins
21+
const ALLOWED_ORIGINS = [
22+
'http://localhost:3000',
23+
'https://wallet.conceal.network',
24+
'https://wws.conceal.network'
25+
];
26+
2027
function sendMessageToParent(type : string, data : any){
21-
window.parent.postMessage({
22-
type:type,
23-
payload:data
24-
}, '*');
28+
// Get the parent origin from referrer or use the production URL as fallback
29+
const parentOrigin = document.referrer ?
30+
new URL(document.referrer).origin :
31+
ALLOWED_ORIGINS[1]; // wallet.conceal.network
32+
33+
// Only send message if the origin is in our allowed list
34+
if (ALLOWED_ORIGINS.includes(parentOrigin)) {
35+
window.parent.postMessage({
36+
type: type,
37+
payload: data
38+
}, parentOrigin);
39+
} else {
40+
console.warn('Attempted to send message to non-allowed origin:', parentOrigin);
41+
}
2542
}
2643

2744
window.addEventListener('message', function(e : MessageEvent){
28-
//console.log(e);
45+
// Verify the origin of the message for security
46+
if (!ALLOWED_ORIGINS.includes(e.origin)) {
47+
console.warn('Received message from non-allowed origin:', e.origin);
48+
return;
49+
}
50+
51+
// Process the message only if it comes from an allowed origin
2952
if(e.data == 'hasWallet'){
3053
sendMessageToParent('hasWallet', WalletRepository.hasOneStored());
3154
}

src/service-worker-raw.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2018 Gnock
33
* Copyright (c) 2018-2019 The Masari Project
44
* Copyright (c) 2018-2020 The Karbo developers
5-
* Copyright (c) 2018-2023 Conceal Community, Conceal.Network & Conceal Devs
5+
* Copyright (c) 2018-2025 Conceal Community, Conceal.Network & Conceal Devs
66
*
77
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
88
*
@@ -23,7 +23,20 @@ __WB_MANIFEST: any[];
2323

2424
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);
2525

26+
// List of allowed origins for cross-origin security
27+
const ALLOWED_ORIGINS = [
28+
'http://localhost:3000',
29+
'https://wallet.conceal.network',
30+
'https://wws.conceal.network'
31+
];
32+
2633
self.addEventListener('message', (event) => {
34+
// Verify the origin of the message for security
35+
if (!ALLOWED_ORIGINS.includes(event.origin)) {
36+
console.warn('Service worker received message from non-allowed origin:', event.origin);
37+
return;
38+
}
39+
2740
if (!event.data){
2841
return;
2942
}

0 commit comments

Comments
 (0)