-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
src: add WDAC integration (Windows) #54364
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
Open
rdw-msft
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
rdw-msft:wldp-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# Code Integrity | ||
|
||
<!--introduced_in=REPLACEME--> | ||
|
||
<!-- type=misc --> | ||
|
||
> Stability: 1.1 - Active development | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This feature is only available on Windows platforms. | ||
|
||
Code integrity refers to the assurance that software code has not been | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
altered or tampered with in any unauthorized way. It ensures that | ||
the code running on a system is exactly what was intended by the developers. | ||
|
||
Code integrity in Node.js integrates with platform features for code integrity | ||
policy enforcement. See platform speficic sections below for more information. | ||
|
||
The Node.js threat model considers the code that the runtime executes to be | ||
trusted. As such, this feature is an additional safety belt, not a strict | ||
security boundary. | ||
|
||
If you find a potential security vulnerability, please refer to our | ||
[Security Policy][]. | ||
|
||
## Code Integrity on Windows | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Code integrity is an opt-in feature that leverages Window Defender Application Control | ||
to verify the code executing conforms to system policy and has not been modified since | ||
signing time. | ||
|
||
There are three audiences that are involved when using Node.js in an | ||
environment enforcing code integrity: the application developers, | ||
those administrating the system enforcing code integrity, and | ||
the end user. The following sections describe how each audience | ||
can interact with code integrity enforcement. | ||
|
||
### Windows Code Integrity and Application Developers | ||
|
||
Windows Defender Application Control uses digital signatures to verify | ||
a file's integrity. Application developers are responsible for generating and | ||
distributing the signature information for their Node.js application. | ||
Application developers are also expected to design their application | ||
in robust ways to avoid unintended code execution. This includes | ||
avoiding the use of `eval` and avoiding loading modules outside | ||
of standard methods. | ||
|
||
Signature information for files which Node.js is intended to execute | ||
can be stored in a catalog file. Application developers can generate | ||
a Windows catalog file to store the hash of all files Node.js | ||
is expected to execute. | ||
|
||
A catalog can be generated using the `New-FileCatalog` Powershell | ||
cmdlet. For example | ||
|
||
```powershell | ||
New-FileCatalog -Version 2 -CatalogFilePath MyApplicationCatalog.cat -Path \my\application\path\ | ||
``` | ||
|
||
The `Path` argument should point to the root folder containing your application's code. If | ||
your application's code is fully contained in one file, `Path` can point to that single file. | ||
|
||
Be sure that the catalog is generated using the final version of the files that you intend to ship | ||
(i.e. after minifying). | ||
|
||
The application developer should then sign the generated catalog with their Code Signing certificate | ||
to ensure the catalog is not tampered with between distribution and execution. | ||
|
||
This can be done with the [Set-AuthenticodeSignature commandlet][]. | ||
|
||
### Windows Code Integrity and System Administrators | ||
|
||
This section is intended for system administrators who want to enable Node.js | ||
code integrity features in their environments. | ||
|
||
This section assumes familiarity with managing WDAC polcies. | ||
[Official documentation for WDAC][]. | ||
|
||
Code integrity enforcement on Windows has two toggleable settings: | ||
`EnforceCodeIntegrity` and `DisableInteractiveMode`. These settings are configured | ||
by WDAC policy. | ||
|
||
`EnforceCodeIntegrity` causes Node.js to call WldpCanExecuteFile whenever a module is loaded using `require`. | ||
WldpCanExecuteFile verifies that the file's integrity has not been tampered with from signing time. | ||
The system administrator should sign and install the application's file catalog where the application | ||
is running, per WDAC guidance. | ||
|
||
`DisableInteractiveMode` prevents Node.js from being run in interactive mode, and also disables the `-e` and `--eval` | ||
command line options. | ||
|
||
#### Enabling Code Integrity Enforcement | ||
|
||
On newer Windows versions (22H2+), the preferred method of configuring application settings is done using | ||
`AppSettings` in your WDAC Policy. | ||
|
||
```text | ||
<AppSettings> | ||
<App Manifest="wdac-manifest.xml"> | ||
<Setting Name="EnforceCodeIntegrity" > | ||
<Value>True</Value> | ||
</Setting> | ||
<Setting Name="DisableInteractiveMode" > | ||
<Value>True</Value> | ||
</Setting> | ||
</App> | ||
</AppSettings> | ||
``` | ||
|
||
On older Windows versions, use the `Settings` section of your WDAC Policy. | ||
|
||
```text | ||
<Settings> | ||
<Setting Provider="Node.js" Key="Settings" ValueName="EnforceCodeIntegrity"> | ||
<Value> | ||
<Boolean>true</Boolean> | ||
</Value> | ||
</Setting> | ||
<Setting Provider="Node.js" Key="Settings" ValueName="DisableInteractiveMode"> | ||
<Value> | ||
<Boolean>true</Boolean> | ||
</Value> | ||
</Setting> | ||
</Settings> | ||
``` | ||
|
||
## Code Integrity on Linux | ||
|
||
Code integrity on Linux is not yet implemented. Plans for implementation will | ||
be made once the necessary APIs on Linux have been upstreamed. More information | ||
can be found here: <https://github.com/nodejs/security-wg/issues/1388> | ||
|
||
## Code Integrity on MacOS | ||
|
||
Code integrity on MacOS is not yet implemented. Currently, there is no | ||
timeline for implementation. | ||
|
||
[Official documentation for WDAC]: https://learn.microsoft.com/en-us/windows/security/application-security/application-control/windows-defender-application-control/ | ||
[Security Policy]: https://github.com/nodejs/node/blob/main/SECURITY.md | ||
[Set-AuthenticodeSignature commandlet]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-authenticodesignature |
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,7 @@ | ||
<!-- Manifest for WDAC integration on Windows. See docs/api/code_integrity.md for | ||
more information regarding WDAC and code integrity --> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<AppManifest Id="Node.js" xmlns="urn:schemas-microsoft-com:windows-defender-application-control"> | ||
<SettingDefinition Name="EnforceCodeIntegrity" Type="Bool" IgnoreAuditPolicies="false"/> | ||
<SettingDefinition Name="DisableInteractiveMode" Type="Bool" IgnoreAuditPolicies="false"/> | ||
</AppManifest> |
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,44 @@ | ||
// Code integrity is a security feature which prevents unsigned | ||
// code from executing. More information can be found in the docs | ||
// doc/api/code_integrity.md | ||
|
||
'use strict'; | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const { emitWarning } = require('internal/process/warning'); | ||
const { | ||
isFileTrustedBySystemCodeIntegrityPolicy, | ||
isInteractiveModeDisabled, | ||
isSystemEnforcingCodeIntegrity, | ||
} = internalBinding('code_integrity'); | ||
|
||
let isCodeIntegrityEnforced; | ||
let alreadyQueriedSystemCodeEnforcmentMode = false; | ||
|
||
function isAllowedToExecuteFile(filepath) { | ||
if (!alreadyQueriedSystemCodeEnforcmentMode) { | ||
isCodeIntegrityEnforced = isSystemEnforcingCodeIntegrity(); | ||
|
||
if (isCodeIntegrityEnforced) { | ||
emitWarning( | ||
'Code integrity is being enforced by system policy.' + | ||
'\nCode integrity is an experimental feature.' + | ||
' See docs for more info.', | ||
'ExperimentalWarning'); | ||
} | ||
|
||
alreadyQueriedSystemCodeEnforcmentMode = true; | ||
} | ||
|
||
if (!isCodeIntegrityEnforced) { | ||
return true; | ||
} | ||
|
||
return isFileTrustedBySystemCodeIntegrityPolicy(filepath); | ||
} | ||
|
||
module.exports = { | ||
isAllowedToExecuteFile, | ||
isFileTrustedBySystemCodeIntegrityPolicy, | ||
isInteractiveModeDisabled, | ||
isSystemEnforcingCodeIntegrity, | ||
}; |
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 |
---|---|---|
|
@@ -23,10 +23,24 @@ const { | |
const { addBuiltinLibsToObject } = require('internal/modules/helpers'); | ||
const { getOptionValue } = require('internal/options'); | ||
|
||
const { | ||
codes: { | ||
ERR_CODE_INTEGRITY_BLOCKED, | ||
}, | ||
} = require('internal/errors'); | ||
|
||
prepareMainThreadExecution(); | ||
addBuiltinLibsToObject(globalThis, '<eval>'); | ||
markBootstrapComplete(); | ||
|
||
const { isWindows } = require('internal/util'); | ||
if (isWindows) { | ||
rdw-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const ci = require('internal/code_integrity'); | ||
if (ci.isInteractiveModeDisabled()) { | ||
throw new ERR_CODE_INTEGRITY_BLOCKED('"eval"'); | ||
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. Am I understanding correctly that this blocks use of |
||
} | ||
} | ||
|
||
const code = getOptionValue('--eval'); | ||
|
||
const print = getOptionValue('--print'); | ||
|
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
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
Oops, something went wrong.
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.