forked from ianstormtaylor/superstruct
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: fix deep sensitive redaction #43
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94370f0
fix: fix deep sensitive redaction
ccharly 5e9e9de
chore: comment
ccharly 63cd199
test: add missing test for arrays
ccharly c86b4f4
fix: fix map case
ccharly 7ae1968
fix: allow undefined map keys
ccharly 4e88633
Merge branch 'main' into cc/fix/fix-deep-sensitive
ccharly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/validation/sensitive/invalid-sibling-ancestor-array.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { array, literal, object, sensitive, string } from '../../../src'; | ||
|
|
||
| // When a sensitive-entries object lives inside an array field, the array | ||
| // itself appears as an ancestor in the branch. The backward walk must handle | ||
| // this by copying the array and replacing the sanitised element, rather than | ||
| // treating it as a plain object with property keys. | ||
| const SecretStruct = object({ | ||
| secret: sensitive(string()), | ||
| encoding: literal('hex'), | ||
| }); | ||
|
|
||
| export const Struct = object({ | ||
| items: array(SecretStruct), | ||
| tag: literal('ok'), | ||
| }); | ||
|
|
||
| export const data = { | ||
| items: [{ secret: 'super-secret', encoding: 'invalid-encoding' }], | ||
| tag: 'ok', | ||
| }; | ||
|
|
||
| export const failures = [ | ||
| { | ||
| value: 'invalid-encoding', | ||
| type: 'literal', | ||
| refinement: undefined, | ||
| path: ['items', 0, 'encoding'], | ||
| branch: [ | ||
| { | ||
| items: [{ secret: '***', encoding: 'invalid-encoding' }], | ||
| tag: 'ok', | ||
| }, | ||
| [{ secret: '***', encoding: 'invalid-encoding' }], | ||
| { secret: '***', encoding: 'invalid-encoding' }, | ||
| 'invalid-encoding', | ||
| ], | ||
| }, | ||
| ]; |
51 changes: 51 additions & 0 deletions
51
test/validation/sensitive/invalid-sibling-ancestor-deep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { literal, object, sensitive, string } from '../../../src'; | ||
|
|
||
| // Three levels of nesting: RootStruct > WrapperStruct > AccountStruct. | ||
| // A sibling failure inside AccountStruct must redact sensitive data from | ||
| // ALL branch entries — including both intermediate and root ancestors. | ||
| const SecretStruct = object({ | ||
| secret: sensitive(string()), | ||
| encoding: literal('hex'), | ||
| }); | ||
|
|
||
| const WrapperStruct = object({ | ||
| account: SecretStruct, | ||
| tag: literal('ok'), | ||
| }); | ||
|
|
||
| export const Struct = object({ | ||
| wrapper: WrapperStruct, | ||
| id: literal('root'), | ||
| }); | ||
|
|
||
| export const data = { | ||
| wrapper: { | ||
| account: { secret: 'super-secret', encoding: 'invalid-encoding' }, | ||
| tag: 'ok', | ||
| }, | ||
| id: 'root', | ||
| }; | ||
|
|
||
| export const failures = [ | ||
| { | ||
| value: 'invalid-encoding', | ||
| type: 'literal', | ||
| refinement: undefined, | ||
| path: ['wrapper', 'account', 'encoding'], | ||
| branch: [ | ||
| { | ||
| wrapper: { | ||
| account: { secret: '***', encoding: 'invalid-encoding' }, | ||
| tag: 'ok', | ||
| }, | ||
| id: 'root', | ||
| }, | ||
| { | ||
| account: { secret: '***', encoding: 'invalid-encoding' }, | ||
| tag: 'ok', | ||
| }, | ||
| { secret: '***', encoding: 'invalid-encoding' }, | ||
| 'invalid-encoding', | ||
| ], | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { literal, map, object, sensitive, string } from '../../../src'; | ||
|
|
||
| // When a sensitive-entries object lives inside a Map, the Map itself appears | ||
| // as an ancestor in the branch. Object.keys() returns [] for Maps, so the | ||
| // backward walk must handle this case by iterating the Map's entries directly. | ||
| const SecretStruct = object({ | ||
| secret: sensitive(string()), | ||
| tag: literal('ok'), | ||
| }); | ||
|
|
||
| export const Struct = map(string(), SecretStruct); | ||
|
|
||
| export const data = new Map([ | ||
| ['key', { secret: 'super-secret', tag: 'INVALID' }], | ||
| ]); | ||
|
|
||
| export const failures = [ | ||
| { | ||
| value: 'INVALID', | ||
| type: 'literal', | ||
| refinement: undefined, | ||
| path: ['key', 'tag'], | ||
| branch: [ | ||
| new Map([['key', { secret: '***', tag: 'INVALID' }]]), | ||
| { secret: '***', tag: 'INVALID' }, | ||
| 'INVALID', | ||
| ], | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { literal, object, sensitive, string } from '../../../src'; | ||
|
|
||
| // When a sensitive() field lives inside a nested object(), a sibling-field | ||
| // failure must redact sensitive data from ALL branch entries — including | ||
| // ancestor objects that hold a reference to the inner (parent) object. | ||
| // Without the fix, branch[0] (the outer wrapper) still exposes secret | ||
| // via its `account` property. | ||
| const SecretStruct = object({ | ||
| secret: sensitive(string()), | ||
| encoding: literal('hex'), | ||
| }); | ||
|
|
||
| export const Struct = object({ | ||
| account: SecretStruct, | ||
| tag: literal('ok'), | ||
| }); | ||
|
|
||
| export const data = { | ||
| account: { secret: 'super-secret', encoding: 'invalid-encoding' }, | ||
| tag: 'ok', | ||
| }; | ||
|
|
||
| export const failures = [ | ||
| { | ||
| value: 'invalid-encoding', | ||
| type: 'literal', | ||
| refinement: undefined, | ||
| path: ['account', 'encoding'], | ||
| branch: [ | ||
| { | ||
| account: { secret: '***', encoding: 'invalid-encoding' }, | ||
| tag: 'ok', | ||
| }, | ||
| { secret: '***', encoding: 'invalid-encoding' }, | ||
| 'invalid-encoding', | ||
| ], | ||
| }, | ||
| ]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.