-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "node_revert.h" | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
namespace node { | ||
|
||
unsigned int reverted = 0; | ||
|
||
const char* RevertMessage(const unsigned int cve) { | ||
#define V(code, label, msg) case REVERT_ ## code: return label ": " msg; | ||
switch (cve) { | ||
REVERSIONS(V) | ||
default: | ||
return "Unknown"; | ||
} | ||
#undef V | ||
} | ||
|
||
void Revert(const unsigned int cve) { | ||
reverted |= 1 << cve; | ||
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve)); | ||
} | ||
|
||
void Revert(const char* cve) { | ||
#define V(code, label, _) \ | ||
do { \ | ||
if (strcmp(cve, label) == 0) { \ | ||
Revert(REVERT_ ## code); \ | ||
return; \ | ||
} \ | ||
} while (0); | ||
REVERSIONS(V) | ||
#undef V | ||
printf("Error: Attempt to revert an unknown CVE [%s]\n", cve); | ||
exit(12); | ||
} | ||
|
||
bool IsReverted(const unsigned int cve) { | ||
return reverted & (1 << cve); | ||
} | ||
|
||
bool IsReverted(const char * cve) { | ||
#define V(code, label, _) \ | ||
do { \ | ||
if (strcmp(cve, label) == 0) \ | ||
return IsReverted(REVERT_ ## code); \ | ||
} while (0); | ||
REVERSIONS(V) | ||
return false; | ||
#undef V | ||
} | ||
|
||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef SRC_NODE_REVERT_H_ | ||
#define SRC_NODE_REVERT_H_ | ||
|
||
#include "node.h" | ||
|
||
/** | ||
* Note that it is expected for this list to vary across specific LTS and | ||
* Stable versions! Only CVE's whose fixes require *breaking* changes within | ||
* a given LTS or Stable may be added to this list, and only with CTC | ||
* consensus. | ||
* | ||
* For *master* this list should always be empty! | ||
* | ||
**/ | ||
#define REVERSIONS(XX) | ||
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title") | ||
|
||
namespace node { | ||
|
||
typedef enum { | ||
#define V(code, _, __) REVERT_ ## code, | ||
REVERSIONS(V) | ||
#undef V | ||
} reversions_t; | ||
|
||
/* A bit field for tracking the active reverts */ | ||
extern unsigned int reverted; | ||
|
||
/* Revert the given CVE (see reversions_t enum) */ | ||
void Revert(const unsigned int cve); | ||
|
||
/* Revert the given CVE by label */ | ||
void Revert(const char* cve); | ||
|
||
/* true if the CVE has been reverted **/ | ||
bool IsReverted(const unsigned int cve); | ||
|
||
/* true if the CVE has been reverted **/ | ||
bool IsReverted(const char * cve); | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_NODE_REVERT_H_ |