如何从电子渲染器进程内存转储中清除敏感的Node.js缓冲区?

时间:2018-12-21 16:03:36

标签: node.js angular electron

我有一个简单的Electron测试应用程序,该应用程序在渲染器进程中运行Angular应用程序。这个有角度的应用程序有两个页面:登录和帐户。使用用户名和密码登录后,您将重定向到帐户页面,然后可以注销。

登录

组件

@Component({
    selector: 'app-login',
    templateUrl: 'login.component.html',
})
export class LoginComponent {
    password: string;
    username: string;

    constructor(private router: Router) {
    }

    submit() {
        let usernameBuffer = Buffer.from(this.username, 'utf8');
        let passwordBuffer = Buffer.from(this.password, 'utf8');

        // Do some Node stuff with the buffers...

        // Now done with the buffers. Clearing the properties like this
        // doesn't seem to help.
        usernameBuffer = null;
        passwordBuffer = null;

        this.router.navigate(['/account']);
    }
}

HTML

<form id="login-page" (ngSubmit)="submit()">
    <label for="username">Username</label><br>
    <input id="username" type="text" name="Username" [(ngModel)]="username" required><br><br>
    <label for="password">Password</label><br>
    <input id="password" type="password" name="Password" [(ngModel)]="password" required><br><br>
    <button type="submit">Log In</button>
</form>

帐户

组件

@Component({
    selector: 'app-account',
    templateUrl: 'account.component.html',
})
export class AccountComponent {
}

HTML

<p>You are logged in!</p>
<p><a routerLink="/login">Log Out</a></p>

测试应用

如果有兴趣,可以在以下位置找到该测试应用程序的完整源代码:https://github.com/kspearrin/electron-memtest。只需克隆它,然后运行npm inpm run electron


使用Windows 10,在用户登录到应用程序并进入帐户页面后,我可以转到任务管理器并执行内存转储以创建.DMP文件。在记事本中打开此.DMP文件,我可以执行搜索并以纯文本格式查看用户名和密码。

在此测试中,我使用用户名“ testusername”和密码“ testpassword-123”登录。

.dmp shows password

仅当我使用用户名和密码数据创建Node Buffers时才会发生,如上LoginComponent所示。缓冲区似乎从未从内存中释放出来。我以为可能最终需要运行Node垃圾收集,但是,我让该应用程序整天运行,并且在创建新的.DMP文件时值仍然存在。也许我需要强制运行垃圾回收?

  1. 为什么这些缓冲区保留在内存中?
  2. 如何正确清理此敏感数据?

1 个答案:

答案 0 :(得分:0)

将它们fill归零:

usernameBuffer.fill(0)
passwordBuffer.fill(0)