Socket
Book a DemoInstallSign in
Socket

@aspecto/privacy-rules

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aspecto/privacy-rules

Aspecto Privacy Rules Engine

latest
Source
npmnpm
Version
0.0.10
Version published
Maintainers
3
Created
Source

Aspecto Privacy Rules

Privacy rules allow to specify which requests or fields need to be blocked or scrambled. Rules are described in a JSON with a certain structure and can be executed by PrivacyEngine.

Example


// specify some rules
const blockRule: PrivacyRuleDef = {
    conditions: [{ conditionType: 'always' }],
    actions: [{ actionType: 'block-request' }],
};

const scrambleFieldRule: PrivacyRuleDef = {
    conditions: [{ conditionType: 'route', conditionData: { filterType: 'by-value', filterValue: '/users/' } }],
    actions: [
        {
            actionType: 'scramble-field',
            actionData: {
                fieldTypes: ['header', 'body-json', 'query-param'],
                filter: { filterType: 'by-key', filterValue: 'Authentication' },
            },
        },
        {
            actionType: 'scramble-field',
            actionData: {
                fieldTypes: ['header', 'body-json', 'query-param'],
                filter: { filterType: 'by-key', filterValue: 'Bearer' },
            },
        },
    ],
};

const blockFieldRule: PrivacyRuleDef = {
    conditions: [{ conditionType: 'service', conditionData: { filterType: 'by-value', filterValue: 'user-service' } }],
    actions: [
        {
            actionType: 'block-field',
            actionData: {
                fieldTypes: ['header', 'body-json', 'query-param'],
                filter: { filterType: 'by-key', filterValue: 'Authentication' },
            },
        },
        {
            actionType: 'block-field',
            actionData: {
                fieldTypes: ['header', 'body-json', 'query-param'],
                filter: { filterType: 'by-key', filterValue: 'Bearer' },
            },
        },
    ],
};

// example message (http request-response)
export const sampleMessage: AspectoMessage = {
    packageName: 'user-service',
    HTTP_REQUEST: {
        route: { path: '/users/' },
        body: { user: 'daniel', password: 'craig' },
        query: {
            auth: 'token',
            param1: 'notprivate',
        },
        requestHeaders: {
            Bearer: 'req-token',
        },
        responseHeaders: {
            Authentication: 'resp-token',
        },
    },
};

// create an instance of the engine, set rules and execute them
const privacyEngine = new PrivacyEngine();
const rules: any[] = [blockRule, blockFieldRule, scrambleFieldRule];
privacyEngine.setRules(rules);
// this will mutate the message, blocking or scrambling certain fields
const result = privacyEngine.executeRules(sampleMessage);

FAQs

Package last updated on 28 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts