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

Add a rudimentary warning to the link share dialog #24

Merged
merged 1 commit into from
Nov 19, 2021
Merged
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
47 changes: 41 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const plugin: JupyterFrontEndPlugin<void> = {
label: trans.__('Share Jupyter Server Link'),
execute: async () => {
let results: { token: string }[];
if (PageConfig.getOption('hubUser') !== '') {
const isRunningUnderJupyterhub = PageConfig.getOption('hubUser') !== '';
if (isRunningUnderJupyterhub) {
// We are running on a JupyterHub, so let's just use the token set in PageConfig.
// Any extra servers running on the server will still need to use this token anyway,
// as all traffic (including any to jupyter-server-proxy) needs this token.
Expand All @@ -67,20 +68,54 @@ const plugin: JupyterFrontEndPlugin<void> = {
const entries = document.createElement('div');
links.map(link => {
const p = document.createElement('p');
const a = document.createElement('a');
a.href = link;
a.innerText = link;
p.appendChild(a);
const text: HTMLInputElement = document.createElement('input');
text.readOnly = true;
text.value = link;
text.addEventListener('click', e => {
(e.target as HTMLInputElement).select();
});
text.style.width = '100%';
p.appendChild(text);
entries.appendChild(p);
});

// Warn users of the security implications of using this link
// FIXME: There *must* be a better way to create HTML
const warning = document.createElement('div');

const warningHeader = document.createElement('h3');
warningHeader.innerText = trans.__('Security warning!');
warning.appendChild(warningHeader);

const messages = [
'Anyone with this link has full access to your notebook server, including all your files!',
jtpio marked this conversation as resolved.
Show resolved Hide resolved
'Please be careful who you share it with.'
];
if (isRunningUnderJupyterhub) {
messages.push(
// You can restart the server to revoke the token in a JupyterHub
'To revoke access, go to File -> Hub Control Panel, and restart your server'
);
} else {
messages.push(
// Elsewhere, you *must* shut down your server - no way to revoke it
'Currently, there is no way to revoke access other than shutting down your server'
);
}
messages.map(m => {
warning.appendChild(document.createTextNode(trans.__(m)));
warning.appendChild(document.createElement('br'));
});

entries.appendChild(warning);

const result = await showDialog({
title: trans.__('Share Jupyter Server Link'),
body: new Widget({ node: entries }),
buttons: [
Dialog.cancelButton({ label: trans.__('Cancel') }),
Dialog.okButton({
label: trans.__('Copy'),
label: trans.__('Copy Link'),
caption: trans.__('Copy the link to the Jupyter Server')
})
]
Expand Down