Skip to content

Add an option for masking query parameters #163

@AE777F63

Description

@AE777F63

Is your feature request related to a problem? Please describe.
The agent has an option to mask sensitive data from headers (filterHttpHeaders); there is no such option for query parameters. It is a common approach to pass things like "key" or "access_token" via query.

Describe the solution you'd like
The agent should provide an option for masking specified query parameters.

Describe alternatives you've considered
Writing a custom filter:

function maskQuery (url, fields, mask = 'REDACTED') {
    const params = new URL(url.full).searchParams;
    const pair = (field, value) => querystring.stringify({ [field]: value });
    // replace field=<SOME SECRET DATA> with field=REDACTED
    const maskField = field => {
        params.getAll(field).forEach(value => {
            const [substr, newstr] = [pair(field, value), pair(field, mask)];
            ['raw', 'search', 'full'].forEach(member => {
                url[member] = url[member].replace(substr, newstr);
            });
        });
    };
    fields.forEach(maskField);
    return url;
}

function transactionFilterQuery (report) {
    if (report.context && report.context.request) {
        try {
            maskQuery(report.context.request.url, ['access_token']);
        } catch (error) {
            logger.error(`URL parsing error: ${JSON.stringify(error)}`);
            report = null;
        }
    }
    return report;
}

apm.addTransactionFilter(transactionFilterQuery);

This, however, needs to be duplicated in every service, requires the URL to be parsed again, and is not very robust. It would be nice to have this functionality provided by the agent directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions