Skip to content
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

src: add process.cveRevert #52090

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ const rawMethods = internalBinding('process_methods');
process.stdin.resume();
return process.stdin;
};

process.cveRevert = rawMethods.cveRevert;
}

const credentials = internalBinding('credentials');
Expand Down
2 changes: 2 additions & 0 deletions src/node_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "v8-fast-api-calls.h"
#include "v8.h"

#define REVERT_PREFIX "REVERT_"

namespace node {

class Environment;
Expand Down
36 changes: 36 additions & 0 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_process-inl.h"
#include "node_revert.h"
#include "util-inl.h"
#include "uv.h"
#include "v8-fast-api-calls.h"
Expand Down Expand Up @@ -499,6 +500,38 @@ static void LoadEnvFile(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}

static void CveRevert(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsString());
Utf8Value cve_string(env->isolate(), args[0]);
std::string revert_error;

Revert(*cve_string, &revert_error);
if (revert_error.empty()) {
// Revert sets the reversion at the C level but we have to
// set the property on the Object as it does not do that
Isolate* isolate = env->isolate();
Local<Context> context = env->context();
#define V(code, label, __) \
do { \
if (strcmp(*cve_string, label) == 0) { \
READONLY_PROPERTY(args.This(), REVERT_PREFIX #code, True(isolate)); \
} \
} while (0);
SECURITY_REVERSIONS(V)
#undef V
}

Local<String> revert_error_return =
String::NewFromUtf8(env->isolate(),
revert_error.c_str(),
NewStringType::kNormal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: might make sense to intern the string, but definitely not critical. Also, these should likely always be one-byte so maybe NewFromOneByte would work to avoid the utf8 transcoding?

revert_error.length())
.ToLocalChecked();
args.GetReturnValue().Set(revert_error_return);
}

namespace process {

BindingData::BindingData(Realm* realm,
Expand Down Expand Up @@ -655,6 +688,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
SetMethod(isolate, target, "patchProcessObject", PatchProcessObject);

SetMethod(isolate, target, "loadEnvFile", LoadEnvFile);
SetMethod(isolate, target, "cveRevert", CveRevert);
}

static void CreatePerContextProperties(Local<Object> target,
Expand Down Expand Up @@ -695,6 +729,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(PatchProcessObject);

registry->Register(LoadEnvFile);

registry->Register(CveRevert);
}

} // namespace process
Expand Down
10 changes: 5 additions & 5 deletions src/node_process_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
GetParentProcessId).FromJust());

// --security-revert flags
#define V(code, _, __) \
do { \
if (IsReverted(SECURITY_REVERT_ ## code)) { \
READONLY_PROPERTY(process, "REVERT_" #code, True(isolate)); \
} \
#define V(code, _, __) \
do { \
if (IsReverted(SECURITY_REVERT_##code)) { \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is from running make format-cpp

READONLY_PROPERTY(process, REVERT_PREFIX #code, True(isolate)); \
} \
} while (0);
SECURITY_REVERSIONS(V)
#undef V
Expand Down
4 changes: 3 additions & 1 deletion src/node_revert.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
**/
namespace node {

#define SECURITY_REVERSIONS(XX) \
#define SECURITY_REVERSIONS(XX) \
XX(CVE_2000_TST1, "CVE-2000-TST1", "First test cve") \
XX(CVE_2000_TST2, "CVE-2000-TST2", "Second test cve")
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")

enum reversion {
Expand Down
Loading