Skip to content

Commit 9f57317

Browse files
Document native AOT security aspects (#42585)
1 parent 5c2f79c commit 9f57317

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Security
3+
description: Learn about security features available with native AOT.
4+
author: MichalStrehovsky
5+
ms.author: michals
6+
ms.date: 09/11/2024
7+
---
8+
9+
# Security features
10+
11+
.NET offers many facilities to help address security concerns when building apps. Native AOT deployment builds on top of these facilities and provides several that can help harden your apps.
12+
13+
## No run-time code generation
14+
15+
Since native AOT generates all code at the time of publishing the app, no new executable code needs to be generated at run time. This allows running your apps in environments that disallow creation of new executable code pages at run time. All the code that the CPU executes can be digitally signed.
16+
17+
## Restricted reflection surface
18+
19+
When apps are published with native AOT, the compiler analyzes the usage of reflection within the app. Only the program elements that were deemed to be targets of reflection are available for reflection at run time. Places within the program that attempt to do unconstrained reflection are flagged using [trimming warnings](../trimming/fixing-warnings.md). Program elements that weren't intended to be targets of reflection cannot be reflected on. This restriction can prevent a class of issues where a malicious actor gets in control of what the program reflects on and invokes unintended code. This restriction includes approaches that use `Assembly.LoadFrom` or `Reflection.Emit` - neither of those work with native AOT, and their use is flagged with a warning at build time.
20+
21+
## Control Flow Guard
22+
23+
[Control Flow Guard](/windows/win32/secbp/control-flow-guard) is a highly optimized platform security feature on Windows that was created to combat memory corruption vulnerabilities. By placing tight restrictions on where an application can execute code from, it makes it much harder for exploits to execute arbitrary code through vulnerabilities such as buffer overflows.
24+
25+
To enable Control Flow Guard on your native AOT app, set the `ControlFlowGuard` property in the published project.
26+
27+
```xml
28+
<PropertyGroup>
29+
<!-- Enable control flow guard -->
30+
<ControlFlowGuard>Guard</ControlFlowGuard>
31+
</PropertyGroup>
32+
```
33+
34+
## Control-flow Enforcement Technology Shadow Stack (.NET 9+)
35+
36+
Control-flow Enforcement Technology (CET) Shadow Stack is a computer processor feature. It provides capabilities to defend against return-oriented programming (ROP) based malware attacks.
37+
38+
CET is enabled by default when publishing for Windows. To disable CET, set the `CetCompat` property in the published project.
39+
40+
```xml
41+
<PropertyGroup>
42+
<!-- Disable Control-flow Enforcement Technology -->
43+
<CetCompat>false</CetCompat>
44+
</PropertyGroup>
45+
```

docs/navigate/devops-testing/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ items:
495495
href: ../../core/deploying/native-aot/libraries.md
496496
- name: Cross-compilation
497497
href: ../../core/deploying/native-aot/cross-compile.md
498+
- name: Security
499+
href: ../../core/deploying/native-aot/security.md
498500
- name: Intro to AOT warnings
499501
href: ../../core/deploying/native-aot/fixing-warnings.md
500502
- name: Intrinsic APIs marked RequiresDynamicCode

0 commit comments

Comments
 (0)