Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@snapshot-labs/snapshot-sentry

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snapshot-labs/snapshot-sentry - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

5

CHANGELOG.md
# Changelog
## v1.3.0
- fix scrubbing not triggered when the regex variable is empty
- accept more `context` signature variations
## v1.2.0

@@ -4,0 +9,0 @@

5

dist/index.d.ts
/// <reference types="node" />
import * as Sentry from '@sentry/node';
import type { Express } from 'express';
export declare function scrubData(exception: Sentry.Exception, regex: RegExp): void;
export declare function sensitiveDataToScrub(collection: NodeJS.ProcessEnv): false | RegExp;
export declare function scrubData(exception: Sentry.Exception, regex?: RegExp): void;
export declare function sensitiveDataToScrub(collection: NodeJS.ProcessEnv): RegExp | undefined;
export declare function initLogger(app?: Express): void;
export declare function fallbackLogger(app?: Express): void;
export declare function capture(e: any, captureContext?: any): void;
export declare function normalizedCaptureContext(captureContext?: any): any;

34

dist/index.js

@@ -26,6 +26,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.capture = exports.fallbackLogger = exports.initLogger = exports.sensitiveDataToScrub = exports.scrubData = void 0;
exports.normalizedCaptureContext = exports.capture = exports.fallbackLogger = exports.initLogger = exports.sensitiveDataToScrub = exports.scrubData = void 0;
const Sentry = __importStar(require("@sentry/node"));
const DEFAULT_TRACE_SAMPLE_RATE = '0.01';
const SCRUB_MASK = '[Filtered]';
const VALID_CONTEXT_KEYS = ['tags', 'extra', 'contexts', 'user', 'level', 'fingerprint'];
const DEFAULT_CONTEXT_TYPE = 'contexts';
const DEFAULT_CONTEXT_CATEGORY = 'input';
function shouldDisable() {

@@ -37,3 +40,5 @@ return !process.env.SENTRY_DSN;

exception.value = exception.value.replaceAll(/\?(apiKey)=[a-zA-Z0-9]+/gi, `?$1=${SCRUB_MASK}`);
exception.value = exception.value.replaceAll(regex, SCRUB_MASK);
if (regex) {
exception.value = exception.value.replaceAll(regex, SCRUB_MASK);
}
}

@@ -48,3 +53,3 @@ }

if (stringsToScrub.length === 0) {
return false;
return;
}

@@ -70,3 +75,2 @@ return new RegExp(stringsToScrub

const regexToScrub = sensitiveDataToScrub(process.env);
console.log(regexToScrub);
Sentry.init({

@@ -78,3 +82,3 @@ dsn: process.env.SENTRY_DSN,

for (const exception of event.exception?.values ?? []) {
regexToScrub && scrubData(exception, regexToScrub);
scrubData(exception, regexToScrub);
}

@@ -109,4 +113,22 @@ return event;

}
Sentry.captureException(e, captureContext);
Sentry.captureException(e, normalizedCaptureContext(captureContext));
}
exports.capture = capture;
function normalizedCaptureContext(captureContext) {
if (!captureContext) {
return;
}
let _captureContext = { ...captureContext };
if (typeof _captureContext === 'object') {
if (!Object.keys(_captureContext).some(k => VALID_CONTEXT_KEYS.includes(k))) {
_captureContext = { [DEFAULT_CONTEXT_TYPE]: _captureContext };
}
if (_captureContext.contexts) {
if (Object.values(_captureContext.contexts).some((vv) => typeof vv !== 'object')) {
_captureContext.contexts = { [DEFAULT_CONTEXT_CATEGORY]: _captureContext.contexts };
}
}
}
return _captureContext;
}
exports.normalizedCaptureContext = normalizedCaptureContext;
{
"name": "@snapshot-labs/snapshot-sentry",
"version": "1.2.0",
"version": "1.3.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -90,3 +90,3 @@ # Snapshot-sentry

// Send the error to sentry
capture(e, { context: { url: url }})
capture(e, { contexts: { input: { url: url } } })
}

@@ -93,0 +93,0 @@ ```

@@ -6,2 +6,5 @@ import * as Sentry from '@sentry/node';

const SCRUB_MASK = '[Filtered]';
const VALID_CONTEXT_KEYS = ['tags', 'extra', 'contexts', 'user', 'level', 'fingerprint'];
const DEFAULT_CONTEXT_TYPE = 'contexts';
const DEFAULT_CONTEXT_CATEGORY = 'input';

@@ -12,6 +15,8 @@ function shouldDisable() {

export function scrubData(exception: Sentry.Exception, regex: RegExp) {
export function scrubData(exception: Sentry.Exception, regex?: RegExp) {
if (exception.value) {
exception.value = exception.value.replaceAll(/\?(apiKey)=[a-zA-Z0-9]+/gi, `?$1=${SCRUB_MASK}`);
exception.value = exception.value.replaceAll(regex, SCRUB_MASK);
if (regex) {
exception.value = exception.value.replaceAll(regex, SCRUB_MASK);
}
}

@@ -27,3 +32,3 @@ }

if (stringsToScrub.length === 0) {
return false;
return;
}

@@ -56,3 +61,3 @@

const regexToScrub = sensitiveDataToScrub(process.env);
console.log(regexToScrub);
Sentry.init({

@@ -64,3 +69,3 @@ dsn: process.env.SENTRY_DSN,

for (const exception of event.exception?.values ?? []) {
regexToScrub && scrubData(exception, regexToScrub);
scrubData(exception, regexToScrub);
}

@@ -100,3 +105,25 @@

Sentry.captureException(e, captureContext);
Sentry.captureException(e, normalizedCaptureContext(captureContext));
}
export function normalizedCaptureContext(captureContext?: any) {
if (!captureContext) {
return;
}
let _captureContext = { ...captureContext };
if (typeof _captureContext === 'object') {
if (!Object.keys(_captureContext).some(k => VALID_CONTEXT_KEYS.includes(k))) {
_captureContext = { [DEFAULT_CONTEXT_TYPE]: _captureContext };
}
if (_captureContext.contexts) {
if (Object.values(_captureContext.contexts).some((vv: any) => typeof vv !== 'object')) {
_captureContext.contexts = { [DEFAULT_CONTEXT_CATEGORY]: _captureContext.contexts };
}
}
}
return _captureContext;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc