microsoft / microsoft/microsoft-ui-xaml
Password from PasswordBox.Password stays in memory indefinitely
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
The `PasswordBox` control leaves the entered password vulnerable in memory.
### Why is this important?
I can not see how this control can be useful if it has such a defect.
### Steps to reproduce the bug
1.) Create a new "WinUI Blank App (Packaged) from the template in Visual Studio.
2.) Replace MainWindwow.cs and MainWindow.xaml.cs:
```cs
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.UI.Xaml;
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string transientPassword = PasswordInput.Password;
Span mutableSpan = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(transientPassword.AsSpan()), transientPassword.Length);
for (int i = 0; i < mutableSpan.Length; i++) { Volatile.Write(ref Unsafe.As(ref mutableSpan[i]), 0); }
PasswordInput.Password = string.Empty;
}
}
```
```xaml
Submit
```
3. Run the app.
4. Enter `helloworld` as password and hit the `Submit` button.
5. Capture a memory dump with Task Manager.
6. Load the Dump into WinDbg.
7. Type `s -u 0 L?-1 "helloworld"` to search for the password in memory.
8. Observe something along the lines:
### Actual behavior
The password despite overwriting it in the part i have control over is still in memory and hanging around for undefined amounts (forever?) of time.
### Expected behavior
The password should be purged from memory.
### Screenshots
_No response_
### NuGet package version
WindowsAppSDK 2.3.1
### Windows version
Windows 11 (25H2): Build 26200
### Additional context
_No response_
Contributor guide
Research direction
Start with the supplied MainWindow.cs and MainWindow.xaml.cs reproduction, then reproduce the issue with the PasswordBox and the WinDbg command `s -u 0 L?-1 "helloworld"`. Trace where PasswordBox.Password is copied or retained and determine whether the expected behavior—purging the entered password from memory—is technically achievable across those copies. Done means the reported password is no longer retained after submission, with coverage for the reproduced scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100