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

fix: add security prompt #842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from './stripeWorkspaceState';
import {Commands} from './commands';
import {Git} from './git';
import {SecurityPrompt} from './securityPrompt';
import {StripeClient} from './stripeClient';
import {StripeDaemon} from './daemon/stripeDaemon';
import {StripeDebugProvider} from './stripeDebugProvider';
Expand All @@ -42,6 +43,7 @@ export function activate(this: any, context: ExtensionContext) {
initializeStripeWorkspaceState(context);

new TelemetryPrompt(context).activate();
new SecurityPrompt(context).activate();
const surveyPrompt: SurveyPrompt = new SurveyPrompt(context);
surveyPrompt.activate();

Expand Down Expand Up @@ -93,7 +95,7 @@ export function activate(this: any, context: ExtensionContext) {
});
stripeHelpView.message = 'This extension runs with your Stripe account in test mode.';

debug.registerDebugConfigurationProvider('stripe', new StripeDebugProvider(telemetry));
debug.registerDebugConfigurationProvider('stripe', new StripeDebugProvider(telemetry, context));

workspace.registerTextDocumentContentProvider(
'stripeEvent',
Expand Down Expand Up @@ -137,8 +139,10 @@ export function activate(this: any, context: ExtensionContext) {
const stripeCommands = new Commands(telemetry, stripeTerminal, context);

const commandCallbackPairs: [string, (...args: any[]) => any][] = [
['stripe.createStripeSample',
(sampleName?: string, integration?: string) => stripeCommands.createStripeSample(stripeSamples, sampleName ?? '', integration ?? ''),
[
'stripe.createStripeSample',
(sampleName?: string, integration?: string) =>
stripeCommands.createStripeSample(stripeSamples, sampleName ?? '', integration ?? ''),
],
['stripe.login', () => stripeCommands.startLogin(stripeDaemon)],
['stripe.openCLI', stripeCommands.openCLI],
Expand Down Expand Up @@ -171,7 +175,12 @@ export function activate(this: any, context: ExtensionContext) {
['stripe.openWebhooksListen', stripeCommands.openWebhooksListen],
[
'stripe.createWebhookEndpoint',
() => stripeCommands.createWebhookEndpoint(stripeDaemon, stripeOutputChannel, stripeWebhooksViewProvider),
() =>
stripeCommands.createWebhookEndpoint(
stripeDaemon,
stripeOutputChannel,
stripeWebhooksViewProvider,
),
],
[
'stripe.resendEvent',
Expand Down Expand Up @@ -209,8 +218,8 @@ export function activate(this: any, context: ExtensionContext) {
console.log('Integration from URI:', integration);
vscode.commands.executeCommand('stripe.createStripeSample', sampleName, integration);
}
}
})
},
}),
);
}

Expand Down
40 changes: 40 additions & 0 deletions src/securityPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as vscode from 'vscode';

enum StorageKeys {
doNotShowSecurityPromptAgain = 'stripeDoNotShowSecurityPromptAgain',
}

export class SecurityPrompt {
storage: vscode.Memento;

constructor(context: vscode.ExtensionContext) {
this.storage = context.globalState;
}

public activate(): void {
if (this.shouldShowBannerOnStartup()) {
this.show();
}
}

public shouldShowBannerOnStartup(): boolean {
if (vscode.workspace.getConfiguration('stripe').has('projectName')) {
return true;
}
return false;
}

public async show() {
if (this.storage.get(StorageKeys.doNotShowSecurityPromptAgain)) {
return;
}
const selection = await vscode.window.showInformationMessage(
"Warning: Debugging from `launch.json` files you didn't create or using code from unofficial sources can expose your system to security risks. Please ensure you understand the implications of the code you are executing.",
'Do not show again',
);
if (!selection) {
return;
}
this.storage.update(StorageKeys.doNotShowSecurityPromptAgain, true);
}
}
8 changes: 7 additions & 1 deletion src/stripeDebugProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable no-warning-comments */
import * as vscode from 'vscode';
import {SecurityPrompt} from './securityPrompt';
import {Telemetry} from './telemetry';

export class StripeDebugProvider implements vscode.DebugConfigurationProvider {
telemetry: Telemetry;
context: vscode.ExtensionContext;

constructor(telemetry: Telemetry) {
constructor(telemetry: Telemetry, context: vscode.ExtensionContext) {
this.telemetry = telemetry;
this.context = context;
vscode.debug.onDidTerminateDebugSession((e: vscode.DebugSession) => {
if (e.name === 'Stripe: Webhooks listen') {
// TODO: Find a way to stop the CLI from the given debug session.
Expand All @@ -28,6 +31,9 @@ export class StripeDebugProvider implements vscode.DebugConfigurationProvider {
) {
this.telemetry.sendEvent('debug.launch');

if (config.forwardTo || config.forwardConnectTo || config.events || config.skipVerify) {
new SecurityPrompt(this.context).show();
}
vscode.commands.executeCommand('stripe.openWebhooksListen', {
forwardTo: config.forwardTo,
forwardConnectTo: config.forwardConnectTo,
Expand Down
Loading