Skip to content

Commit 8370952

Browse files
authored
Display error message when running kernels from untrusted locations (#11624)
* Display error message when running kernels from untrusted locations * Update change log and version
1 parent 91f4038 commit 8370952

30 files changed

+311
-141
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## 2022.9.120 (11 October 2022)
4+
### Enhancements
5+
1. Display an error message (with instructions to resolve the issue) in the cell output when attempting to run a cell against a kernel from an untrusted location.
6+
([#11622](https://github.com/Microsoft/vscode-jupyter/issues/11622))
7+
8+
### Thanks
9+
10+
Thanks to the following projects which we fully rely on to provide some of
11+
our features:
12+
13+
- [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
14+
- [debugpy](https://pypi.org/project/debugpy/)
15+
16+
Also thanks to the various projects we provide integrations with which help
17+
make this extension useful:
18+
19+
- [Jupyter](https://jupyter.org/):
20+
[Notebooks](https://jupyter-notebook.readthedocs.io/en/latest/?badge=latest),
21+
[JupyterHub](https://jupyterhub.readthedocs.io/en/stable/),
22+
[ipywidgets](https://ipywidgets.readthedocs.io/en/latest/),
23+
[nbconvert](https://nbconvert.readthedocs.io/en/latest/)
24+
325
## 2022.9.110 (11 October 2022)
426
### Fixes
527
1. Fixed vulnerability described in [CVE-2022-41083](https://msrc.microsoft.com/update-guide/vulnerability/CVE-2022-41083)

build/azure-pipeline.stable.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ extends:
3939
- script: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r ./requirements.txt
4040
displayName: Install Python libs
4141

42-
# - script: npm run updateBuildNumber
43-
# displayName: Update build number
42+
- script: npm run updateBuildNumber
43+
displayName: Update build number
4444

4545
- script: npm run prePublishBundleStable
4646
displayName: Build

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jupyter",
33
"displayName": "Jupyter",
4-
"version": "2022.9.1100000000",
4+
"version": "2022.9.120",
55
"description": "Jupyter notebook support, interactive programming and computing that supports Intellisense, debugging and more.",
66
"publisher": "ms-toolsai",
77
"author": {

package.nls.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,7 @@
844844
"message": "Failed to interrupt the Kernel.",
845845
"comment": ["{Locked='Kernel'}"]
846846
},
847-
"DataScience.updateSettingToTrustKernelSpecs": "Update setting to trust kernels",
848-
"DataScience.untrustedKernelSpecsHidden": "Kernels found in an insecure location have not been loaded.",
847+
"DataScience.failedToStartAnUntrustedKernelSpec": "The kernel '{0}' was not started as it is located in an insecure location '{1}'. \nClick [here](https://aka.ms/JupyterTrustedKernelPaths) for further details, optionally update the setting [jupyter.kernels.trusted](command:workbench.action.openSettings?[\"jupyter.kernels.trusted\"]) to trust the kernel.",
849848
"jupyter.configuration.jupyter.kernels.trusted.markdownDescription": "Enter fully qualified paths to Kernel specification files that are to be trusted. E.g. 'C:\\Program Data\\Jupyter\\kernels\\python3\\kernel.json'. \n**Note**: Kernels can execute code with user privileges. Click [here](https://aka.ms/JupyterTrustedKernelPaths) for further details.",
850849
"DataScience.kernelDied": {
851850
"message": "The kernel died. View Jupyter [log](command:jupyter.viewOutput) for further details. \nError: {0}...",

src/interactive-window/debugger/jupyter/debuggingManager.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { buildSourceMap } from '../helper';
4141
import { noop } from '../../../platform/common/utils/misc';
4242
import { IInteractiveWindowDebuggingManager } from '../../types';
4343
import { IControllerLoader, IControllerSelection } from '../../../notebooks/controllers/types';
44+
import { IServiceContainer } from '../../../platform/ioc/types';
4445

4546
/**
4647
* The DebuggingManager maintains the mapping between notebook documents and debug sessions.
@@ -61,9 +62,18 @@ export class InteractiveWindowDebuggingManager
6162
@inject(IDebugLocationTrackerFactory)
6263
private readonly debugLocationTrackerFactory: IDebugLocationTrackerFactory,
6364
@inject(IConfigurationService) private readonly configService: IConfigurationService,
64-
@inject(IDebugService) private readonly debugService: IDebugService
65+
@inject(IDebugService) private readonly debugService: IDebugService,
66+
@inject(IServiceContainer) serviceContainer: IServiceContainer
6567
) {
66-
super(kernelProvider, controllerLoader, controllerSelection, commandManager, appShell, vscNotebook);
68+
super(
69+
kernelProvider,
70+
controllerLoader,
71+
controllerSelection,
72+
commandManager,
73+
appShell,
74+
vscNotebook,
75+
serviceContainer
76+
);
6777
}
6878

6979
public override async activate(): Promise<void> {

src/kernels/errors/kernelErrorHandler.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,21 @@ function getUserFriendlyErrorMessage(error: Error | string, errorContext?: Kerne
453453
return getCombinedErrorMessage(errorPrefix, errorMessage);
454454
}
455455
}
456+
function doesErrorHaveMarkdownLinks(message: string) {
457+
const markdownLinks = new RegExp(/\[([^\[]+)\]\((.*)\)/);
458+
return (markdownLinks.exec(message)?.length ?? 0) > 0;
459+
}
456460
function getCombinedErrorMessage(prefix?: string, message?: string) {
457461
const errorMessage = [prefix || '', message || '']
458462
.map((line) => line.trim())
459463
.filter((line) => line.length > 0)
460464
.join(' \n');
461-
if (errorMessage.length && errorMessage.indexOf('command:jupyter.viewOutput') === -1) {
465+
466+
if (
467+
!doesErrorHaveMarkdownLinks(errorMessage) &&
468+
errorMessage.length &&
469+
errorMessage.indexOf('command:jupyter.viewOutput') === -1
470+
) {
462471
return `${
463472
errorMessage.endsWith('.') ? errorMessage : errorMessage + '.'
464473
} \n${DataScience.viewJupyterLogForFurtherInfo()}`;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { Uri } from 'vscode';
5+
import { getDisplayPath } from '../../platform/common/platform/fs-paths';
6+
import { DataScience } from '../../platform/common/utils/localize';
7+
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
8+
import { LocalKernelConnectionMetadata } from '../types';
9+
import { WrappedKernelError } from './types';
10+
11+
/**
12+
* Thrown when we attempt to start a kernel that is not trusted.
13+
*/
14+
export class KernelSpecNotTrustedError extends WrappedKernelError {
15+
constructor(kernelConnectionMetadata: LocalKernelConnectionMetadata) {
16+
super(
17+
DataScience.failedToStartAnUntrustedKernelSpec().format(
18+
getDisplayNameOrNameOfKernelConnection(kernelConnectionMetadata),
19+
kernelConnectionMetadata.kernelSpec.specFile
20+
? getDisplayPath(Uri.file(kernelConnectionMetadata.kernelSpec.specFile))
21+
: ''
22+
),
23+
undefined,
24+
kernelConnectionMetadata
25+
);
26+
}
27+
}

src/kernels/hiddenKernelNotification.node.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/kernels/raw/finder/jupyterPaths.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class JupyterPaths {
303303
paths.add(winPath);
304304
}
305305

306-
if (process.env.ALLUSERSPROFILE) {
307-
paths.add(Uri.file(path.join(process.env.ALLUSERSPROFILE, 'jupyter', 'kernels')));
306+
if (process.env.PROGRAMDATA) {
307+
paths.add(Uri.file(path.join(process.env.PROGRAMDATA, 'jupyter', 'kernels')));
308308
}
309309
} else {
310310
// Unix based

0 commit comments

Comments
 (0)