diff --git a/frontend/components/Editor.js b/frontend/components/Editor.js index 2afb63b4e..2cc44e550 100644 --- a/frontend/components/Editor.js +++ b/frontend/components/Editor.js @@ -699,6 +699,24 @@ export class Editor extends Component { const { message } = await this.client.send("nbpkg_available_versions", { package_name: package_name }, { notebook_id: notebook_id }) return message }, + disable_safe_preview: async (maybe_confirm = false, notebook_state_mutator = (_) => {}) => { + const warn_about_untrusted_code = this.client.session_options?.security?.warn_about_untrusted_code ?? true + let source = this.state.notebook.metadata?.risky_file_source + + if ( + !warn_about_untrusted_code || + !maybe_confirm || + source == null || + confirm(`⚠️ Danger! Are you sure that you trust this file? \n\n${source}\n\nA malicious notebook can steal passwords and data.`) + ) { + await this.update_notebook((notebook) => { + delete notebook.metadata.risky_file_source + notebook_state_mutator(notebook) + }) + } else { + throw new Error("User did not confirm disabling safe preview") + } + }, } this.actions = { ...this.real_actions } @@ -1531,29 +1549,20 @@ The notebook file saves every time you run a cell.` ` } - const warn_about_untrusted_code = this.client.session_options?.security?.warn_about_untrusted_code ?? true - const restart = async (maybe_confirm = false) => { - let source = notebook.metadata?.risky_file_source - if ( - !warn_about_untrusted_code || - !maybe_confirm || - source == null || - confirm(`⚠️ Danger! Are you sure that you trust this file? \n\n${source}\n\nA malicious notebook can steal passwords and data.`) - ) { - await this.actions.update_notebook((notebook) => { - delete notebook.metadata.risky_file_source - }) - await this.client.send( - "restart_process", - {}, - { - notebook_id: notebook.notebook_id, - } - ) - } + await this.actions.disable_safe_preview(maybe_confirm) + // (the call above will throw if no permission is given) + await this.client.send( + "restart_process", + {}, + { + notebook_id: notebook.notebook_id, + } + ) } + const warn_about_untrusted_code = this.client.session_options?.security?.warn_about_untrusted_code ?? true + const restart_button = (text, maybe_confirm = false) => html` restart(maybe_confirm)}>${text}` diff --git a/frontend/components/Popup.js b/frontend/components/Popup.js index 316c37abd..3e2a27966 100644 --- a/frontend/components/Popup.js +++ b/frontend/components/Popup.js @@ -8,6 +8,7 @@ import { useDebouncedTruth } from "./RunArea.js" import { time_estimate, usePackageTimingData } from "../common/InstallTimeEstimate.js" import { pretty_long_time } from "./EditOrRunButton.js" import { useEventListener } from "../common/useEventListener.js" +import { ProcessStatus } from "../common/ProcessStatus.js" // This funny thing is a way to tell parcel to bundle these files.. // Eventually I'll write a plugin that is able to parse html`...`, but this is it for now. @@ -244,7 +245,7 @@ const PkgPopup = ({ notebook, recent_event, clear_recent_event, disable_input }) ` : null}