Gathering detailed insights and metrics for data-guardian
Gathering detailed insights and metrics for data-guardian
Gathering detailed insights and metrics for data-guardian
Gathering detailed insights and metrics for data-guardian
request-guardian
`request-guardian` is a middleware function that validates incoming requests against a set of validation rules using `express-validator`. It can be used to ensure that data sent to a server is in the expected format and meets certain criteria. If the vali
theta-data
Theta Data is a Data Explorer and Analytics Tool for Theta Network. It collects data from Guardian Node, performs analysis and provides data and analysis result through convenient Graphql interfaces. Users can access the data with simple statements and qu
@olton/guardian
Data validator
@guardian/guration
A module that allows you to validate drag and drop actions on a tree of data, culminating in 'edits' that describe the modification on a normalized data structure.
Tiny, zero-dependencies, package which tries to mask sensitive data in arbitrary collections (map, set), errors, objects and strings.
npm install data-guardian
Typescript
Module System
Min. Node Version
72.3
Supply Chain
98.9
Quality
76.7
Maintenance
100
Vulnerability
100
License
Total
13,436
Last Day
10
Last Week
423
Last Month
1,287
Last Year
12,493
14 Stars
51 Commits
1 Forks
2 Watching
9 Branches
1 Contributors
Updated on 30 Nov 2024
Minified
Minified + Gzipped
TypeScript (73.9%)
HTML (21.66%)
CSS (4.44%)
Cumulative downloads
Total Downloads
Last day
-52.4%
10
Compared to previous day
Last week
80%
423
Compared to previous week
Last month
12.6%
1,287
Compared to previous month
Last year
1,224.8%
12,493
Compared to previous year
data-guardian
is a nimble, zero-dependency and lightweight NPM package crafted for developers who prioritize data security and privacy. This handy utility enables you to mask sensitive strings and object properties, safeguarding critical data from prying eyes, especially in logs or UI displays. Notably, it maintains the immutability of your data by default, though this feature is optional and customizable based on your needs.
data-guardian
is a lightweight package that won't slow down your app.data-guardian
is written in TypeScript and comes with full type definitions.1npm install data-guardian
Here's a quick peek at how data-guardian
can be integrated into your JavaScript/TypeScript projects:
1const { maskData, maskString, maskArguments } = require('data-guardian'); 2 3// Masking a string 4console.log(maskString('SensitiveData123!')); 5// Output: "Se************123!" 6 7console.log(maskString('connection to postgres://dbuser:SuperSecretPassword!@localhost:5432/mydb established')); 8// output: "connection to po****es://db**er:Su**************************st:5432/mydb established" 9 10// Masking an arbitary string with sensitive data 11console.log(maskString('a dude once exposed his super secret A1vbcvc.De#3435?r password to the world but luckily we could help')); 12// Output: "a dude once exposed his super secret A1***********35?r password to the world but luckily we could help" 13 14// Masking object's properties 15const user = { username: 'johndoe', password: 'SuperSecretPassword!' }; 16console.log(maskData(user)); 17// Output: { username: 'johndoe', password: 'Su***************d!' } 18 19// Masking arguments list 20console.log(maskArguments(['SensitiveArgument1', 'SensitiveArgument2'])); 21// Output: ["Se*****************1", "Se*****************2"]
By default, data-guardian
masks the following data types in free-form strings and object properties:
By default, data-guardian
preserves the immutability of your data, meaning your original input remains untouched. However, if you prefer to alter the original data, you can do so by setting the immutability option to false
.
1const user = { password: 'SuperSecretPassword!' }; 2maskData(user, { immutable: false }); // This will mutate the `user` object 3console.log(user); 4// Output: { password: 'Su***************d!' }
With data-guardian, you're not limited to the predefined sensitive data types! You can extend its functionality by providing your own custom regular expressions for identifying and masking sensitive data in strings, or by providing a custom function to determine which keys to mask in objects:
1// Define a custom regex that identifies a pattern "customSensitiveData: any-text-here" 2const customRegExp = { customPattern: /customSensitiveData:\s*(\S+)/gi }; 3 4const data = { 5 id: 1, 6 name: 'Test Name', 7 customField: 'customSensitiveData: verySensitive' 8}; 9console.log(maskData(data, { customSensitiveContentRegExp: customRegExp })); 10// Output: { id: 1, name: 'Test Name', customField: 'cu******************************ve' } 11 12// Custom regular expressions for string masking 13const customPatterns = { 14 secretCode: /my-secret-code-\d{3}/gi, // matches 'my-secret-code-123', 'my-secret-code-456', etc. 15}; 16 17console.log(maskString('Here is my-secret-code-123!', { customPatterns })); 18// Output: "Here is my-*********-123!" 19 20const customMaskingLogic = (key) => { 21// add your custom logic here. Return true for keys you want to mask 22return ['customSensitiveKey', 'anotherSensitiveKey'].includes(key); 23}; 24 25const data = { customSensitiveKey: 'HideThis', anotherSensitiveKey: 'AndThis', normalKey: 'ButNotThis' }; 26console.log(maskData(data, { keyCheck: customMaskingLogic })); 27// Output: { customSensitiveKey: 'Hi******s', anotherSensitiveKey: 'An******s', normalKey: 'ButNotThis' }
Masking Data in a Map, Set, and Error Instances
data-guardian
extends its masking capabilities to Map, Set, and Error instances as well. Below are examples illustrating how to mask sensitive data stored in these structures:
1const sensitiveMap = new Map(); 2sensitiveMap.set('username', 'johndoe'); 3sensitiveMap.set('password', 'SuperSecretPassword!'); 4 5const maskedMap = maskData(sensitiveMap); 6console.log(Array.from(maskedMap.entries())); 7// Output: [["username", "johndoe"], ["password", "Su***************d!"]]
1const sensitiveSet = new Set(['SensitiveData1', 'SensitiveData2']); 2const maskedSet = maskData(sensitiveSet); 3console.log(Array.from(maskedSet)); 4// Output: ["Se**************1", "Se**************2"]
1const sensitiveError = new Error('Sensitive message containing user password: SuperSecretPassword!'); 2const maskedError = maskData(sensitiveError); 3console.log(maskedError.message); 4// Output: "Sensitive message containing user password: Su***************d!"
Remember, when working with Maps, the immutable option is especially handy as it prevents the original Map from being altered, ensuring data integrity and consistency across your application.
data-guardian
allows for custom configuration through the IMaskDataOptions
interface. You can specify a custom function to determine which keys to mask in objects, set a custom masking character, and define the length of characters to mask out among other options:
1const customMaskingConfig = { 2 keyCheck: (key) => key.includes('Sensitive'), 3 maskingChar: '#', 4 maskLength: 10, 5}; 6 7const data = { 8 id: 1, 9 SensitiveInfo: 'VerySensitiveData', 10}; 11 12console.log(maskData(data, customMaskingConfig)); 13// Output: { id: 1, SensitiveInfo: 'Very##########Data' }
data-guardian
allows for exclusion of certain matchers. This is useful when you want to mask all sensitive data except for a few. For example, you may want to mask all sensitive data except for the password in a URI.
1const exampleString = 'I do not want to mask my credit card number 1234-5678-9012-3456 but my password SuperSecretPassword should not be visible'; 2console.log(maskString(exampleString, { excludeMatchers: ['creditCard'] })); 3// Output: "I do not want to mask my credit card number 1234-5678-9012-3456 but my password Su***************rd should not be visible"
data-guardian
allows for explicit bypassing masking of potential sensitive content in strings by wrapping the content with '##'
1const exampleString = 'SpanWidth01 is invalid!'; 2console.log(maskString(exampleString)); 3// Output: "Sp*******01 is invalid!" 4 5const exampleNonMaskedString = '##SpanWidth01## is invalid!'; 6console.log(maskString(exampleNonMaskedString)); 7// Output: "SpanWidth01 is invalid!" 8 9console.log(maskData({ username: 'johndoe', password: '##SuperSecretPassword!##' })); 10// Output: { username: 'johndoe', password: 'SuperSecretPassword!' } 11
This section provides detailed information about the functions available in the Sensitive Content Masker library.
SensitiveContentKey
An alias for the keys of the sensitiveContentRegExp object.
1declare const sensitiveContentRegExp: { 2 readonly uuid: RegExp; 3 readonly creditCard: RegExp; 4 readonly ssn: RegExp; 5 readonly url: RegExp; 6 readonly ipv4: RegExp; 7 readonly email: RegExp; 8 readonly passwordSubstring: RegExp; 9 readonly password: RegExp; 10 readonly passwordInUri: RegExp; 11 readonly passwordMention: RegExp; 12};
A union type representing the characters that can be used for masking. Can be one of the following characters:
1type MaskingChar = 'X' | 'x' | '$' | '/' | '.' | '*' | '#' | '+' | '@' | '-' | '_' | ' ';
An interface representing the available options for masking.
keyCheck (function): A function that checks if a key should have its value masked. Accepts a string and returns a boolean.
immutable (boolean): Whether the original data structure should be preserved, and an entirely new one created. Default is true.
customPatterns (object): An object where keys are custom types and values are RegExp objects used for identifying sensitive content.
maskingChar (MaskingChar): The character used for masking content.
maskLength (number): The length of the mask to apply on the sensitive content.
types (SensitiveContentKey[]): The types of sensitive content to check for.
customSensitiveContentRegExp (object): An object similar to customPatterns, but used only in certain masking contexts.
fixedMaskLength (boolean): When enabled, masks the sensitive content with a fixed number of characters. Default is 'false'.
excludeMatchers (SensitiveContentKey[]): The types of sensitive content to exclude from masking.
maskString(value: string, options?: Partial<IMaskOptions>): string
Masks sensitive parts of a string based on the provided options.
value
(string): The string containing potential sensitive content that needs to be masked.options
(PartialmaskData<T>(data: T, options?: Partial<IMaskOptions>): T
Recursively masks sensitive data in an object, array, or any other nested structure based on the provided options. Will not mask objects with circular references.
data
(T): The data structure containing potential sensitive information. It could be an object, array, Map, Set, etc.options
(PartialmaskString
function. Additionally, it uses the keyCheck
function to decide if an object's key should have its value masked, based on the key name.immutable
is false, it alters the original data; otherwise, it returns a new instance.These functions are generic and designed to handle various types of data structures, ensuring sensitive information is adequately masked while retaining the original data format and type.
maskArguments(func: (...args: any[]) => any, options?: Partial<IMaskOptions>): (...args: any[]) => any
Wraps a function and masks sensitive information within the arguments passed to it, based on the provided options. This is particularly useful for logging or monitoring systems where function arguments may contain sensitive data.
func
(Function): The original function that will be called with the masked arguments. This function takes any number of arguments and can return any type of data.options
(PartialThe maskArguments
function is essential for scenarios where sensitive information might be passed to functions that log, transmit, or manipulate this data in ways that could lead to exposure. By masking arguments automatically, this method helps maintain data privacy and security without requiring significant changes to existing codebases.
data-guardian
is designed to provide an additional layer of security by masking strings and object properties that contain sensitive information. However, it is not a substitute for comprehensive security practices. Ensure you follow industry standards and regulations for data protection and privacy.
If you have ideas on how to improve data-guardian
or want to report a bug, please open an issue or submit a pull request. We appreciate your help and contributions!
MIT
No vulnerabilities found.
No security vulnerabilities found.