-
Notifications
You must be signed in to change notification settings - Fork 255
Make URL Redaction more dynamic #2716
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
Changes from 12 commits
e0651b7
8d1de51
b4d41fd
781fa52
9a25f45
53aa2c8
8368977
ddc2531
0859848
1822734
7af28dc
72c224b
8fd3800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { createEnumStyle } from "../EnumHelperFuncs"; | ||
|
|
||
| /** | ||
| * Controls how the user can configure which parts of the URL should be redacted. Example, certain query parameters, username and password, etc. | ||
| */ | ||
|
|
||
| export const enum eUrlRedactionOptions { | ||
| /** | ||
| * The default value, will redact the username and password as well as the default set of query parameters | ||
| */ | ||
| true = 1, | ||
|
|
||
| /** | ||
| * Does not redact username and password or any query parameters, the URL will be left as is. Note: this is not recommended as it may lead | ||
| * to sensitive data being sent in clear text. | ||
| */ | ||
| false = 2, | ||
|
|
||
| /** | ||
| * This will append any additional queryParams that the user has provided through redactQueryParams config to the default set i.e to | ||
| * @defaultValue ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature"]. | ||
| */ | ||
| appendToDefault = 3, | ||
|
|
||
| /** | ||
| * This will replace the default set of query parameters to redact with the query parameters defined in redactQueryParams config, if provided by the user. | ||
| */ | ||
| replaceDefault = 4, | ||
|
|
||
| /** | ||
| * This will redact username and password in the URL but will not redact any query parameters, even those in the default set. | ||
| */ | ||
| usernamePasswordOnly = 5, | ||
|
|
||
| /** | ||
| * This will only redact the query parameter in the default set of query parameters to redact. It will not redact username and password. | ||
| */ | ||
| queryParamsOnly = 6, | ||
|
|
||
| } | ||
|
|
||
| export const UrlRedactionOptions = (/* @__PURE__ */ createEnumStyle<typeof eUrlRedactionOptions>({ | ||
| /** | ||
| * The default value, will redact the username and password as well as the default set of query parameters | ||
| */ | ||
| true: eUrlRedactionOptions.true, | ||
|
|
||
| /** | ||
| * Does not redact username and password or any query parameters, the URL will be left as is. Note: this is not recommended as it may lead | ||
| * to sensitive data being sent in clear text. | ||
| */ | ||
| false: eUrlRedactionOptions.false, | ||
|
|
||
| /** | ||
| * This will append any additional queryParams that the user has provided through redactQueryParams config to the default set i.e to | ||
| * @defaultValue ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature"]. | ||
| */ | ||
| appendToDefault: eUrlRedactionOptions.appendToDefault, | ||
|
|
||
| /** | ||
| * This will replace the default set of query parameters to redact with the query parameters defined in redactQueryParams config, if provided by the user. | ||
| */ | ||
| replaceDefault: eUrlRedactionOptions.replaceDefault, | ||
|
|
||
| /** | ||
| * This will redact username and password in the URL but will not redact any query parameters, even those in the default set. | ||
| */ | ||
| usernamePasswordOnly: eUrlRedactionOptions.usernamePasswordOnly, | ||
|
|
||
| /** | ||
| * This will only redact the query parameter in the default set of query parameters to redact. It will not redact username and password. | ||
| */ | ||
| queryParamsOnly: eUrlRedactionOptions.queryParamsOnly, | ||
|
|
||
| })); | ||
|
|
||
| export type UrlRedactionOptions = boolean | eUrlRedactionOptions; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |
| isFunction, isNullOrUndefined, isString, isUndefined, mathMax, strIndexOf, strSubstring | ||
| } from "@nevware21/ts-utils"; | ||
| import { DEFAULT_SENSITIVE_PARAMS, STR_EMPTY, STR_REDACTED } from "../constants/InternalConstants"; | ||
| import { UrlRedactionOptions } from "../enums/ai/UrlRedactionOptions"; | ||
| import { IConfiguration } from "../interfaces/ai/IConfiguration"; | ||
| import { strContains } from "./HelperFuncs"; | ||
|
|
||
|
|
@@ -455,8 +456,12 @@ function redactQueryParameters(url: string, config?: IConfiguration): string { | |
| return url; | ||
| } | ||
|
|
||
| if (config && config.redactQueryParams) { | ||
| const option = config ? config.redactUrls : undefined; | ||
|
MSNev marked this conversation as resolved.
|
||
|
|
||
| if (option === UrlRedactionOptions.appendToDefault) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these ones should be referencing the |
||
| sensitiveParams = DEFAULT_SENSITIVE_PARAMS.concat(config.redactQueryParams); | ||
| } else if (option === UrlRedactionOptions.replaceDefault) { | ||
| sensitiveParams = config.redactQueryParams; | ||
| } else { | ||
| sensitiveParams = DEFAULT_SENSITIVE_PARAMS; | ||
|
rads-1996 marked this conversation as resolved.
|
||
| } | ||
|
|
@@ -543,17 +548,30 @@ export function fieldRedaction(input: string, config: IConfiguration): string { | |
| if (!input || !isString(input) || strIndexOf(input, " ") !== -1) { | ||
| return input; | ||
| } | ||
| const isRedactionDisabled = config && config.redactUrls === false; | ||
|
|
||
| const option = config ? config.redactUrls : undefined; | ||
|
|
||
| const isRedactionDisabled = option === false || option === UrlRedactionOptions.false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same again use the const enum
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add all other references
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you mean "And all other references" |
||
| if (isRedactionDisabled) { | ||
| return input; | ||
| } | ||
| const hasCredentials = strIndexOf(input, "@") !== -1; | ||
| const hasQueryParams = strIndexOf(input, "?") !== -1; | ||
|
|
||
| let hasCredentials = strIndexOf(input, "@") !== -1; | ||
| let hasQueryParams = strIndexOf(input, "?") !== -1; | ||
|
|
||
| // If no credentials and no query params, return original | ||
| if (!hasCredentials && !hasQueryParams) { | ||
| return input; | ||
| } | ||
|
|
||
| if (option === UrlRedactionOptions.usernamePasswordOnly) { | ||
| hasQueryParams = false; | ||
| } | ||
|
|
||
| if (option === UrlRedactionOptions.queryParamsOnly) { | ||
| hasCredentials = false; | ||
| } | ||
|
|
||
| try { | ||
| let result = input; | ||
| if (hasCredentials) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.