-
Notifications
You must be signed in to change notification settings - Fork 49.4k
[Flight] Taint APIs #27445
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
[Flight] Taint APIs #27445
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5074fbd
Add Feature Flag
sebmarkbage 1710e07
Add taintValue and taintShallowObject APIs
sebmarkbage d722243
Register tainted values with the registry
sebmarkbage c34003d
Check the registry before serializing
sebmarkbage a37bd86
Optimize binary value checking
sebmarkbage 8d914ac
Test
sebmarkbage d4f1c3f
Keep values alive until the end of any pending requests
sebmarkbage 4f2c039
Rename APIs
sebmarkbage c2e8442
Typo
sebmarkbage 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
Add taintValue and taintShallowObject APIs
- Loading branch information
commit 1710e076b57a6acb326e610511ff4f6da204c6e8
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
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
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,88 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {enableTaint} from 'shared/ReactFeatureFlags'; | ||
import ReactSharedInternals from 'shared/ReactSharedInternals'; | ||
|
||
const TaintRegistry = ReactSharedInternals.TaintRegistry; | ||
|
||
interface Reference {} | ||
|
||
const TypedArrayConstructor = Object.getPrototypeOf(Uint8Array.prototype); | ||
|
||
const defaultMessage = | ||
'A tainted value was attempted to be serialized to a Client Component or Action closure. ' + | ||
'This would leak it to the client.'; | ||
|
||
export function taintValue( | ||
message: ?string, | ||
lifetime: Reference, | ||
value: string | bigint | $ArrayBufferView, | ||
): void { | ||
if (!enableTaint) { | ||
throw new Error('Not implemented.'); | ||
} | ||
// eslint-disable-next-line react-internal/safe-string-coercion | ||
message = '' + (message || defaultMessage); | ||
if ( | ||
lifetime === null || | ||
(typeof lifetime !== 'object' && typeof lifetime !== 'function') | ||
) { | ||
throw new Error( | ||
'To taint a value, a life time must be defined by passing an object that holds ' + | ||
'the value.', | ||
); | ||
} | ||
if (typeof value === 'string') { | ||
return; | ||
} | ||
if (typeof value === 'bigint') { | ||
return; | ||
} | ||
if (value instanceof TypedArrayConstructor) { | ||
return; | ||
} | ||
if (value instanceof DataView) { | ||
return; | ||
} | ||
const kind = value === null ? 'null' : typeof value; | ||
if (kind === 'object' || kind === 'function') { | ||
throw new Error( | ||
'taintValue cannot taint objects or functions. Try taintShallowObject instead.', | ||
); | ||
} | ||
throw new Error( | ||
'Cannot taint a ' + | ||
kind + | ||
' because the value is too general and cannot be ' + | ||
'a secret by', | ||
); | ||
} | ||
|
||
export function taintShallowObject(message: ?string, object: Reference): void { | ||
if (!enableTaint) { | ||
throw new Error('Not implemented.'); | ||
} | ||
// eslint-disable-next-line react-internal/safe-string-coercion | ||
message = '' + (message || defaultMessage); | ||
if (typeof object === 'string' || typeof object === 'bigint') { | ||
throw new Error( | ||
'Only objects or functions can be passed to taintShallowObject. Try taintValue instead.', | ||
); | ||
} | ||
if ( | ||
object === null || | ||
(typeof object !== 'object' && typeof object !== 'function') | ||
) { | ||
throw new Error( | ||
'Only objects or functions can be passed to taintShallowObject.', | ||
); | ||
} | ||
// TODO | ||
} |
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,10 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export const TaintRegistry: {} = {}; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lifetime