flawopen.com/Teardowns/cve-2023-32558-nodejs-permission-model-fs-escape
vulnerabilidade に関する技術的なソースコード解析と堅牢化対策:脆弱性の根本原因と安全な実装パッチの詳細。
直感的な物理的アナロジー解説:Imagine a high-security office building with security guards at the front doors checking badges. A worker who doesn't have a badge walks around back, opens the maintenance door marked 'Internal Staff Only', and walks straight into the vault. In Node.js, the developer guarded the public JavaScript functions, but forgot to lock the underlying C++ internal door.
Node.js Permission Model--permission CLI flag restricting process capabilities like filesystem, child process, and worker access.process.binding()Path ContainmentDefense-in-Depth根本原因は、オープンソースシステムにおける未検証の境界パラメータに起因し、状態の非同期化とセキュリティ制御の迂回を可能にします。
技術的な脆弱性悪用メカニズムと実行フローの詳細:A developer runs untrusted code with node --permission --allow-fs-read=/tmp app.js.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The script invokes const binding = process.binding('fs');.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The script calls binding.open('/etc/passwd') directly, bypassing fs.readFile() wrappers.
技術的な脆弱性悪用メカニズムと実行フローの詳細:The native C++ binding executes without permission checks, leaking confidential server files.
// VULNERABLE: src/node_file.cc before patch
static void Open(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
// ROOT CAUSE:
// Only verified permissions if called through JS 'fs' module wrappers!
// Direct callers of process.binding('fs').open() evaded the check!
const char* path = *Utf8Value(env->isolate(), args[0]);
int fd = uv_fs_open(..., path, ...);
args.GetReturnValue().Set(fd);
}
// SECURE: src/node_file.cc patch
static void Open(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
const char* path = *Utf8Value(env->isolate(), args[0]);
// 1. Enforce permission verification directly inside native C++ binding layer
if (env->permission()->is_enabled()) {
if (!env->permission()->is_granted(PermissionScope::kFileSystemRead, path)) {
THROW_ERR_ACCESS_DENIED(env, "Access to path %s denied by Permission Model", path);
return;
}
}
int fd = uv_fs_open(..., path, ...);
args.GetReturnValue().Set(fd);
}
process.binding() and internal Node.js modules from user-space code を無効化または制限してください。