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

feat(connect-popup): call method via URL params #14044

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
59 changes: 59 additions & 0 deletions packages/connect-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@

// global method used in html-inline elements
window.closeWindow = () => {
if (urlParams.get('method')) return;
setTimeout(() => {
window.postMessage(
{
Expand All @@ -613,3 +614,61 @@
window.close();
}, 300);
};

// POC get method from search param
// http://localhost:8088/popup.html?method=getAddress&params=%7B%22path%22:%22m/49%27/0%27/0%27/0/0%22%7D&callback=https://httpbin.org/get
const urlParams = new URLSearchParams(window.location.search);
const method = urlParams.get('method');
if (method) {
const settings = parseConnectSettings(
{
connectSrc: location.href.split('popup.html')[0], // testing
debug: true,
transports: ['WebUsbTransport', 'BridgeTransport'],
},
window.origin, // TODO set origin properly, while allowing WebUSB cross-origin
);
console.log('settings', settings);
addWindowEventListener(
'message',
(event: MessageEvent<any>) => {
console.log('event', event.data);
if (event.data.type === POPUP.CORE_LOADED) {
handleMessageInCoreMode({
data: {
type: POPUP.HANDSHAKE,
payload: {
settings,
},
},
} as any);
handleMessageInCoreMode({
data: {
id: 1,
type: IFRAME.CALL,
payload: {
method,
...(urlParams.get('params')
? JSON.parse(urlParams.get('params')!)
: undefined),
},
},
} as any);
}
if (event.data.type === RESPONSE_EVENT) {
console.log('response', event.data);
const callback = urlParams.get('callback');
if (callback) {
location.href = `${callback}?response=${encodeURIComponent(JSON.stringify(event.data.payload))}`;

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.
}
}
},
false,
);
await init({
settings,
systemInfo: getSystemInfo(config.supportedBrowsers),
useBroadcastChannel: false,
useCore: true,
});
}
Loading