Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,13 @@ export class AdapterConfig<T extends SettingsDefinitionMap = SettingsDefinitionM
)
.map(([name]) => ({
key: name,
// Escaping potential special characters in values before creating regex
value: new RegExp(
((this.settings as Record<string, ValidSettingValue>)[name]! as string).replace(
/[-[\]{}()*+?.,\\^$|#\s]/g,
'\\$&',
),
((this.settings as Record<string, ValidSettingValue>)[name]! as string)
// Escaping potential special characters in values before creating regex
.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
// Escaping special case for new line characters. This is needed to properly match and censor private keys,
// ssh keys, and other multi-line string values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

.replace(/\n/g, '\\n'),
'gi',
),
}))
Expand Down
42 changes: 41 additions & 1 deletion test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
SettingsDefinitionMap,
} from '../src/config'
import { validator } from '../src/validation/utils'
import { Adapter } from '../src/adapter'
import { buildSettingsList } from '../src/util/settings'

test.afterEach(async () => {
process.env = {}
Expand Down Expand Up @@ -168,7 +170,7 @@ test.serial('Test validate function (scientific notation)', async (t) => {
}
})

test('sensitive configuration constants are properly flagged', (t) => {
test.serial('sensitive configuration constants are properly flagged', (t) => {
// Extract all settings that are marked as sensitive
const actualSensitiveSettings = Object.entries(BaseSettingsDefinition)
.filter(([_, setting]) => (setting as { sensitive?: boolean }).sensitive === true)
Expand All @@ -187,3 +189,41 @@ test('sensitive configuration constants are properly flagged', (t) => {
// Deep equal comparison
t.deepEqual(actualSensitiveSettings, expectedSensitiveSettings)
})

test.serial('multiline sensitive configuration constants are properly redacted', async (t) => {
// GIVEN
process.env['PRIVATE_KEY'] =
'-----BEGIN PRIVATE KEY-----\nthis\nis a fake\nprivate key\nused for testing only==\n-----END PRIVATE KEY-----'
const customSettings: SettingsDefinitionMap = {
PRIVATE_KEY: {
description: 'Test custom env var',
type: 'string',
sensitive: true,
validate: {
meta: {
details: 'placeholder validation',
},
fn: (_?: string) => {
return ''
},
},
},
}
const config = new AdapterConfig(customSettings)
config.initialize()
config.validate()
config.buildCensorList()

const adapter = new Adapter({
name: 'TEST_ADAPTER',
endpoints: [],
config: config,
})

const settingsList = buildSettingsList(adapter)

const settingEntries = settingsList.filter((entry) => entry.name === 'PRIVATE_KEY')
t.assert(settingEntries.length === 1)
const settingEntry = settingEntries[0]
t.assert(settingEntry.value === '[PRIVATE_KEY REDACTED]')
})
Loading