Skip to content

Commit da3750f

Browse files
committed
src: add --security-revert command line flag
The `--security-revert={cvenum}` command line flag is a special purpose flag to be used only in stable or LTS branches when a breaking change is required to address a security vulnerability. Whenever a vulnerability requires a breaking change, and a CVE has been assigned, the flag can be used to force Node to revert to the insecure behavior that was implemented before the fix was applied. Note that this flag is intended to be used only as a last resort in the case a security update breaks existing code. When used, a security warning will be printed to stderr when Node launches. The `--security-revert={cvenum}` flag takes a single CVE number as an argument. Multiple instances of the `--security-revert={cvenum}` flag can be used on the command line to revert multiple changes. Whenever a new `--security-revert={cvenum}` is enabled, it should be documented in the release notes and in the API docs. Master and the first release of a new major (e.g. v6.0) should not have any reverts available. Every time a new `--security-revert={cvenum}` is added, there should be a semver-minor bump in the stable and LTS branch. PR-URL: nodejs-private/node-private#20
1 parent 1c4ea61 commit da3750f

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

node.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
'src/node_javascript.cc',
118118
'src/node_main.cc',
119119
'src/node_os.cc',
120+
'src/node_revert.cc',
120121
'src/node_util.cc',
121122
'src/node_v8.cc',
122123
'src/node_stat_watcher.cc',
@@ -156,6 +157,7 @@
156157
'src/node_version.h',
157158
'src/node_watchdog.h',
158159
'src/node_wrap.h',
160+
'src/node_revert.h',
159161
'src/node_i18n.h',
160162
'src/pipe_wrap.h',
161163
'src/tty_wrap.h',

src/node.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node_javascript.h"
77
#include "node_version.h"
88
#include "node_internals.h"
9+
#include "node_revert.h"
910

1011
#if defined HAVE_PERFCTR
1112
#include "node_counters.h"
@@ -2976,6 +2977,16 @@ void SetupProcessObject(Environment* env,
29762977
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
29772978
}
29782979

2980+
// --security-revert flags
2981+
#define V(code, _, __) \
2982+
do { \
2983+
if (IsReverted(REVERT_ ## code)) { \
2984+
READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \
2985+
} \
2986+
} while (0);
2987+
REVERSIONS(V)
2988+
#undef V
2989+
29792990
size_t exec_path_len = 2 * PATH_MAX;
29802991
char* exec_path = new char[exec_path_len];
29812992
Local<String> exec_path_value;
@@ -3339,6 +3350,9 @@ static void ParseArgs(int* argc,
33393350
track_heap_objects = true;
33403351
} else if (strcmp(arg, "--throw-deprecation") == 0) {
33413352
throw_deprecation = true;
3353+
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
3354+
const char* cve = arg + 18;
3355+
Revert(cve);
33423356
} else if (strcmp(arg, "--v8-options") == 0) {
33433357
new_v8_argv[new_v8_argc] = "--help";
33443358
new_v8_argc += 1;

src/node_revert.cc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "node_revert.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
namespace node {
6+
7+
unsigned int reverted = 0;
8+
9+
const char* RevertMessage(const unsigned int cve) {
10+
#define V(code, label, msg) case REVERT_ ## code: return label ": " msg;
11+
switch (cve) {
12+
REVERSIONS(V)
13+
default:
14+
return "Unknown";
15+
}
16+
#undef V
17+
}
18+
19+
void Revert(const unsigned int cve) {
20+
reverted |= 1 << cve;
21+
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
22+
}
23+
24+
void Revert(const char* cve) {
25+
#define V(code, label, _) \
26+
do { \
27+
if (strcmp(cve, label) == 0) { \
28+
Revert(REVERT_ ## code); \
29+
return; \
30+
} \
31+
} while (0);
32+
REVERSIONS(V)
33+
#undef V
34+
printf("Error: Attempt to revert an unknown CVE [%s]\n", cve);
35+
exit(12);
36+
}
37+
38+
bool IsReverted(const unsigned int cve) {
39+
return reverted & (1 << cve);
40+
}
41+
42+
bool IsReverted(const char * cve) {
43+
#define V(code, label, _) \
44+
do { \
45+
if (strcmp(cve, label) == 0) \
46+
return IsReverted(REVERT_ ## code); \
47+
} while (0);
48+
REVERSIONS(V)
49+
return false;
50+
#undef V
51+
}
52+
53+
} // namespace node

src/node_revert.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef SRC_NODE_REVERT_H_
2+
#define SRC_NODE_REVERT_H_
3+
4+
#include "node.h"
5+
6+
/**
7+
* Note that it is expected for this list to vary across specific LTS and
8+
* Stable versions! Only CVE's whose fixes require *breaking* changes within
9+
* a given LTS or Stable may be added to this list, and only with CTC
10+
* consensus.
11+
*
12+
* For *master* this list should always be empty!
13+
*
14+
**/
15+
#define REVERSIONS(XX)
16+
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
17+
18+
namespace node {
19+
20+
typedef enum {
21+
#define V(code, _, __) REVERT_ ## code,
22+
REVERSIONS(V)
23+
#undef V
24+
} reversions_t;
25+
26+
/* A bit field for tracking the active reverts */
27+
extern unsigned int reverted;
28+
29+
/* Revert the given CVE (see reversions_t enum) */
30+
void Revert(const unsigned int cve);
31+
32+
/* Revert the given CVE by label */
33+
void Revert(const char* cve);
34+
35+
/* true if the CVE has been reverted **/
36+
bool IsReverted(const unsigned int cve);
37+
38+
/* true if the CVE has been reverted **/
39+
bool IsReverted(const char * cve);
40+
41+
} // namespace node
42+
43+
#endif // SRC_NODE_REVERT_H_

0 commit comments

Comments
 (0)