Skip to content

Commit 67353fe

Browse files
committed
hardening
- Linux hardening flags (all builds): -fstack-protector-strong - Stack canary protection -fPIC - Position Independent Code -Wl,-z,relro,-z,now - Full RELRO (Read-only GOT) - Linux Release-only flags (via configurations.Release): _FORTIFY_SOURCE=2 - Buffer overflow detection -fcf-protection=full - Control Flow Integrity (Intel CET) - macOS hardening flags (all builds): -fstack-protector-strong in OTHER_CFLAGS - Windows hardening flags (all builds): BufferSecurityCheck: "true" (/GS) ControlFlowGuard: "Guard" (/guard:cf) /DYNAMICBASE - ASLR support /NXCOMPAT - DEP/NX bit support - Windows Release-only flags: /sdl - Additional security checks
1 parent 859747d commit 67353fe

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

binding.gyp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"xcode_settings": {
1212
"CLANG_CXX_LIBRARY": "libc++",
1313
"MACOSX_DEPLOYMENT_TARGET": "10.7",
14+
"OTHER_CFLAGS": [ "-fstack-protector-strong" ]
1415
},
1516
"include_dirs": [
1617
"<!@(node -p \"require('node-addon-api').include\")"],
@@ -39,15 +40,54 @@
3940
"deps/sqlite3.gyp:sqlite3"
4041
]
4142
}
42-
]
43+
],
44+
# Linux hardening flags (apply to all builds)
45+
["OS=='linux'", {
46+
"cflags+": [
47+
"-fstack-protector-strong",
48+
"-fPIC"
49+
],
50+
"ldflags+": [ "-Wl,-z,relro,-z,now" ]
51+
}],
52+
# Windows hardening flags (apply to all builds)
53+
["OS=='win'", {
54+
"msvs_settings": {
55+
"VCCLCompilerTool": {
56+
"ExceptionHandling": 1,
57+
"BufferSecurityCheck": "true",
58+
"ControlFlowGuard": "Guard"
59+
},
60+
"VCLinkerTool": {
61+
"AdditionalOptions": [ "/DYNAMICBASE", "/NXCOMPAT" ]
62+
}
63+
}
64+
}]
4365
],
4466
"sources": [
4567
"src/backup.cc",
4668
"src/database.cc",
4769
"src/node_sqlite3.cc",
4870
"src/statement.cc"
4971
],
50-
"defines": [ "NAPI_VERSION=<(napi_build_version)" ]
72+
"defines": [ "NAPI_VERSION=<(napi_build_version)" ],
73+
# Release-specific hardening flags
74+
"configurations": {
75+
"Release": {
76+
"conditions": [
77+
["OS=='linux'", {
78+
"defines+": [ "_FORTIFY_SOURCE=2" ],
79+
"cflags+": [ "-fcf-protection=full" ]
80+
}],
81+
["OS=='win'", {
82+
"msvs_settings": {
83+
"VCCLCompilerTool": {
84+
"AdditionalOptions": [ "/sdl" ]
85+
}
86+
}
87+
}]
88+
]
89+
}
90+
}
5191
}
5292
]
5393
}

0 commit comments

Comments
 (0)