8
8
"io/ioutil"
9
9
"os"
10
10
"strconv"
11
+ "strings"
11
12
12
13
securityAgent "github.com/newrelic/csec-go-agent"
13
14
"github.com/newrelic/go-agent/v3/internal"
@@ -31,6 +32,11 @@ func defaultSecurityConfig() SecurityConfig {
31
32
cfg .Security .Agent .Enabled = true
32
33
cfg .Security .Detection .Rxss .Enabled = true
33
34
cfg .Security .Request .BodyLimit = 300
35
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Header = make ([]string , 0 )
36
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Body = make ([]string , 0 )
37
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Query = make ([]string , 0 )
38
+ cfg .Security .ExcludeFromIastScan .API = make ([]string , 0 )
39
+ cfg .Security .ScanControllers .IastScanRequestRateLimit = 3600
34
40
return cfg
35
41
}
36
42
@@ -63,7 +69,7 @@ func InitSecurityAgent(app *newrelic.Application, opts ...ConfigOption) error {
63
69
64
70
appConfig , isValid := app .Config ()
65
71
if ! isValid {
66
- return fmt .Errorf ("Newrelic application value cannot be read; did you call newrelic.NewApplication?" )
72
+ return fmt .Errorf ("Newrelic application value cannot be read; did you call newrelic.NewApplication?" )
67
73
}
68
74
app .UpdateSecurityConfig (c .Security )
69
75
if ! appConfig .HighSecurity && isSecurityAgentEnabled () {
@@ -109,8 +115,24 @@ func ConfigSecurityFromYaml() ConfigOption {
109
115
// NEW_RELIC_SECURITY_VALIDATOR_SERVICE_URL provides URL for the security validator service
110
116
// NEW_RELIC_SECURITY_MODE scanning mode: "IAST" for now
111
117
// NEW_RELIC_SECURITY_AGENT_ENABLED (boolean)
112
- // NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED (boolean)
113
118
// NEW_RELIC_SECURITY_REQUEST_BODY_LIMIT (integer) set limit on read request body in kb. By default, this is "300"
119
+ //
120
+ // NEW_RELIC_SECURITY_SCAN_SCHEDULE_DELAY (integer) The delay field indicated time in minutes before the IAST scan starts after the application starts. By default is 0 min.
121
+ // NEW_RELIC_SECURITY_SCAN_SCHEDULE_DURATION (integer) The duration field specifies the duration of the IAST scan in minutes. This determines how long the scan will run. By default is forever.
122
+ // NEW_RELIC_SECURITY_SCAN_SCHEDULE_SCHEDULE (string) The schedule field specifies a cron expression that defines when the IAST scan should run.
123
+ // NEW_RELIC_SECURITY_SCAN_SCHEDULE_ALWAYS_SAMPLE_TRACES (boolean) always_sample_traces permits IAST to actively gather trace data in the background, and the collected data will be used by Security Agent to perform an IAST Scan at the scheduled time.
124
+ // NEW_RELIC_SECURITY_SCAN_CONTROLLERS_IAST_SCAN_REQUEST_RATE_LIMIT (integer) The IAST Scan Rate Limit settings limit the maximum number of analysis probes or requests that can be sent to the application in a minute, By default is 3600.
125
+ //
126
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_INSECURE_SETTINGS (boolean)
127
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_INVALID_FILE_ACCESS (boolean)
128
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_SQL_INJECTION (boolean)
129
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_NOSQL_INJECTION (boolean)
130
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_LDAP_INJECTION (boolean)
131
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_JAVASCRIPT_INJECTION (boolean)
132
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_COMMAND_INJECTION (boolean)
133
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_XPATH_INJECTION (boolean)
134
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_SSRF (boolean)
135
+ // NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_RXSS (boolean)
114
136
115
137
func ConfigSecurityFromEnvironment () ConfigOption {
116
138
return func (cfg * SecurityConfig ) {
@@ -145,6 +167,37 @@ func ConfigSecurityFromEnvironment() ConfigOption {
145
167
assignBool (& cfg .Security .Agent .Enabled , "NEW_RELIC_SECURITY_AGENT_ENABLED" )
146
168
assignBool (& cfg .Security .Detection .Rxss .Enabled , "NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED" )
147
169
assignInt (& cfg .Security .Request .BodyLimit , "NEW_RELIC_SECURITY_REQUEST_BODY_LIMIT" )
170
+
171
+ assignInt (& cfg .Security .ScanSchedule .Delay , "NEW_RELIC_SECURITY_SCAN_SCHEDULE_DELAY" )
172
+ assignInt (& cfg .Security .ScanSchedule .Duration , "NEW_RELIC_SECURITY_SCAN_SCHEDULE_DURATION" )
173
+ assignString (& cfg .Security .ScanSchedule .Schedule , "NEW_RELIC_SECURITY_SCAN_SCHEDULE_SCHEDULE" )
174
+ assignBool (& cfg .Security .ScanSchedule .AllowIastSampleCollection , "NEW_RELIC_SECURITY_SCAN_SCHEDULE_ALWAYS_SAMPLE_TRACES" )
175
+ assignInt (& cfg .Security .ScanControllers .IastScanRequestRateLimit , "NEW_RELIC_SECURITY_SCAN_CONTROLLERS_IAST_SCAN_REQUEST_RATE_LIMIT" )
176
+
177
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .InsecureSettings , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_INSECURE_SETTINGS" )
178
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .InvalidFileAccess , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_INVALID_FILE_ACCESS" )
179
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .SQLInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_SQL_INJECTION" )
180
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .NosqlInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_NOSQL_INJECTION" )
181
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .LdapInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_LDAP_INJECTION" )
182
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .JavascriptInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_JAVASCRIPT_INJECTION" )
183
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .CommandInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_COMMAND_INJECTION" )
184
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .XpathInjection , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_XPATH_INJECTION" )
185
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .Ssrf , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_SSRF" )
186
+ assignBool (& cfg .Security .ExcludeFromIastScan .IastDetectionCategory .Rxss , "NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_IAST_DETECTION_CATEGORY_RXSS" )
187
+
188
+ if env := os .Getenv ("NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_API" ); env != "" {
189
+ cfg .Security .ExcludeFromIastScan .API = strings .Split (env , "," )
190
+ }
191
+ if env := os .Getenv ("NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_HTTP_REQUEST_PARAMETERS_HEADER" ); env != "" {
192
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Header = strings .Split (env , "," )
193
+ }
194
+ if env := os .Getenv ("NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_HTTP_REQUEST_PARAMETERS_QUERY" ); env != "" {
195
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Query = strings .Split (env , "," )
196
+ }
197
+ if env := os .Getenv ("NEW_RELIC_SECURITY_EXCLUDE_FROM_IAST_SCAN_HTTP_REQUEST_PARAMETERS_BODY" ); env != "" {
198
+ cfg .Security .ExcludeFromIastScan .HttpRequestParameters .Body = strings .Split (env , "," )
199
+ }
200
+
148
201
}
149
202
}
150
203
@@ -182,3 +235,43 @@ func ConfigSecurityRequestBodyLimit(bodyLimit int) ConfigOption {
182
235
cfg .Security .Request .BodyLimit = bodyLimit
183
236
}
184
237
}
238
+
239
+ // ConfigScanScheduleDelay is used to set delay for scan schedule.
240
+ // The delay field indicated time in minutes before the IAST scan starts after the application starts
241
+ func ConfigScanScheduleDelay (delay int ) ConfigOption {
242
+ return func (cfg * SecurityConfig ) {
243
+ cfg .Security .ScanSchedule .Delay = delay
244
+ }
245
+ }
246
+
247
+ // ConfigScanScheduleDuration is used to set duration for scan schedule.
248
+ // The duration field specifies the duration of the IAST scan in minutes. This determines how long the scan will run.
249
+ func ConfigScanScheduleDuration (duration int ) ConfigOption {
250
+ return func (cfg * SecurityConfig ) {
251
+ cfg .Security .ScanSchedule .Duration = duration
252
+ }
253
+ }
254
+
255
+ // ConfigScanScheduleSetSchedule is used to set schedule for scan schedule.
256
+ // The schedule field specifies a cron expression that defines when the IAST scan should run.
257
+ func ConfigScanScheduleSetSchedule (schedule string ) ConfigOption {
258
+ return func (cfg * SecurityConfig ) {
259
+ cfg .Security .ScanSchedule .Schedule = schedule
260
+ }
261
+ }
262
+
263
+ // ConfigScanScheduleAllowIastSampleCollection is used to allow or disallow IAST sample collection
264
+ // always_sample_traces permits IAST to actively gather trace data in the background, and the collected data will be used by Security Agent to perform an IAST Scan at the scheduled time.
265
+ func ConfigScanScheduleAllowIastSampleCollection (isAllowed bool ) ConfigOption {
266
+ return func (cfg * SecurityConfig ) {
267
+ cfg .Security .ScanSchedule .AllowIastSampleCollection = isAllowed
268
+ }
269
+ }
270
+
271
+ // ConfigScanControllersIastScanRequestRateLimit is used to set IAST scan request rate limit.
272
+ // The IAST Scan Rate Limit settings limit the maximum number of analysis probes or requests that can be sent to the application in a minute
273
+ func ConfigIastScanRequestRateLimit (limit int ) ConfigOption {
274
+ return func (cfg * SecurityConfig ) {
275
+ cfg .Security .ScanControllers .IastScanRequestRateLimit = limit
276
+ }
277
+ }
0 commit comments