Skip to content

Commit

Permalink
Merge pull request #33 from newrelic/dev
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
aayush-ap authored Jan 15, 2024
2 parents 80d63e2 + d305fe7 commit 16d5280
Show file tree
Hide file tree
Showing 38 changed files with 353 additions and 155 deletions.
20 changes: 20 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## [v0.6.0] - 2024-15-01
### Changes
* Added exclusion based filtering of RXSS events.
* Added ws headers NR-CSEC-ENTITY-GUID and NR-CSEC-ENTITY-NAME.
* Added Support for PUT, PATCH and DELETE http requests type. NR-175410
* Added Support for FastHttp framework.
* Implemented API to send important logs to Security Engine.
* Added support for warning messages in case of missing security wrappers
* Updated jsonVersion to 1.1.1 in security events.
* Updated example/test application directory.
* Updated unit test-cases for mongo.
* Updated file access hook and sent absolute file path.
### Changes
* Incorrect query type for mongo findAndModify case.
* Fixed empty complete request ID for lastleg .
* Incorrect server protocol in case of grpc.
* Nil query for sql prepared statement for MAC environment.
* Fixed for NPE in case of outbound request.


## [v0.5.1] - 2023-11-16
### Bug Fixes
* Added required changes for backward compatibility with APM agent.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ For the latest version of the agent, Go 1.17+ is required.
* labstack/echo
* julienschmidt/httprouter
* micro/go-micro
* valyala/fasthttp

### Databases

Expand Down
28 changes: 28 additions & 0 deletions examples/sample-vulnerable-application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#### examples/sample-vulnerable-application
sample-vulnerable-application is a vulnerable web application designed for demo and reference.
#### WARNING!
---
sample-vulnerable-application is a vulnerable web application.

**Use it for demo purposes only, run it only on test environment.**

#### Setup
```
git clone https://github.com/newrelic/csec-go-agent.git
cd examples/sample-vulnerable-application
```
#### Install dependency packages

```
go mod init test
go mod download
```

#### Run application
```
go run main.go
```

#### Accessing the application :
The application can be accessed at `http://HOST_MACHINE_IP:8000`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: New Relic Pre-Release

// warning! sample-vulnerable-application is a vulnerable web application.Use it for demo purposes only, run it only on test environment
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/csec_antchfx_htmlquery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_antchfx_htmlquery
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_antchfx_jsonquery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_antchfx_jsonquery
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_antchfx_xmlquery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_antchfx_xmlquery
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_antchfx_xpath/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_antchfx_xpath
go 1.16

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_augustoroman_v8/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_augustoroman_v8
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_grpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_grpc
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
github.com/golang/protobuf v1.5.3
Expand Down
3 changes: 2 additions & 1 deletion instrumentation/csec_grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ func (k *SecGrpcServe) secServe(l net.Listener) error {
}

func init() {
secIntercept.InitGrpsFuzzRestClient(SecGrpcFuzz{})

if !secIntercept.IsAgentInitializedForHook() || secIntercept.IsForceDisable() || !secIntercept.IsHookingoIsSupported() {
return
}

e := secIntercept.HookWrapInterface((*grpc.Server).Serve, (*SecGrpcServe).secServe, (*SecGrpcServe).secServe_s)
secIntercept.IsHookedLog("(*grpc.Server).Serve", e)
secIntercept.InitGrpsFuzzRestClient(SecGrpcFuzz{})
}
8 changes: 5 additions & 3 deletions instrumentation/csec_grpc/sec_grpc_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

secUtils "github.com/newrelic/csec-go-agent/internal/security_utils"
secConfig "github.com/newrelic/csec-go-agent/security_config"
secevent "github.com/newrelic/csec-go-agent/security_event_generation"
sechandler "github.com/newrelic/csec-go-agent/security_handlers"
Expand All @@ -24,11 +25,12 @@ type SecGrpcFuzz struct {

func (grpcFuzz SecGrpcFuzz) ExecuteFuzzRequest(fuzzRequest *sechandler.FuzzRequrestHandler, caseType string, fuzzId string) {
fuzzRequestID := fmt.Sprintf("%v", fuzzRequest.Headers[secIntercept.NR_CSEC_FUZZ_REQUEST_ID])

sechandler.FuzzHandler.AppendCompletedRequestIds(fuzzId, "")
var grpcBody []interface{}
err := json.Unmarshal([]byte(fuzzRequest.Body), &grpcBody)
if err != nil {
logger.Debugln("ERROR: error in unmarshal gRPC body : ", err.Error(), fuzzRequest.Body)
secIntercept.SendLogMessage("ERROR: error in unmarshal gRPC body : "+err.Error(), "csec_grpc")
secevent.SendFuzzFailEvent(fuzzRequestID)
return
}
Expand All @@ -55,6 +57,7 @@ func (grpcFuzz SecGrpcFuzz) ExecuteFuzzRequest(fuzzRequest *sechandler.FuzzRequr

if err != nil {
logger.Errorln("ERROR: Failed to create fuzz client : ", secConfig.GlobalInfo.ApplicationInfo.ServerIp, gPort, err.Error())
secIntercept.SendLogMessage("ERROR: Failed to create fuzz client : "+secConfig.GlobalInfo.ApplicationInfo.ServerIp+gPort+err.Error(), "csec_grpc")
secevent.SendFuzzFailEvent(fuzzRequestID)
}

Expand All @@ -63,7 +66,6 @@ func (grpcFuzz SecGrpcFuzz) ExecuteFuzzRequest(fuzzRequest *sechandler.FuzzRequr
url = url[1:]
}

sechandler.FuzzHandler.AppendCompletedRequestIds(fuzzId, "")
tmp := fmt.Sprintf("%s: %s", "nr-csec-parent-id", fuzzId)
headers = append(headers, tmp)

Expand All @@ -89,7 +91,7 @@ func (grpcFuzz SecGrpcFuzz) ExecuteFuzzRequest(fuzzRequest *sechandler.FuzzRequr
}

func getFuzzClient(protocol, url, serverName string) (*grpc.ClientConn, error) {
if protocol == "https" {
if secUtils.CaseInsensitiveEquals(protocol, "https") {
return getHttpsClient(url, serverName)
} else {
return getHttpClient(url)
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/csec_ldap_v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_ldap_v3

go 1.17
require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
12 changes: 0 additions & 12 deletions instrumentation/csec_mongodb_mongo/csec_mongodb_mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestMongoInsertOneHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -63,7 +62,6 @@ func TestMongoInsertManyHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -92,7 +90,6 @@ func TestMongoFindHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -130,7 +127,6 @@ func TestMongoFindOneHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -163,7 +159,6 @@ func TestMongoFindOneAndReplaceHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -192,7 +187,6 @@ func TestMongoFindOneAndUpdateHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -222,7 +216,6 @@ func TestMongoFindOneAndDeleteHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -251,7 +244,6 @@ func TestMongoUpdateOneHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -280,7 +272,6 @@ func TestMongoUpdateManyHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -310,7 +301,6 @@ func TestMongoReplaceOneHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -340,7 +330,6 @@ func TestMongoDeleteOneHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down Expand Up @@ -369,7 +358,6 @@ func TestMongoDeleteManyHook(t *testing.T) {
secConfig.RegisterListener()

mt := ConnectMongoDB(t)
defer mt.Close()

mt.Run("success", func(mt *mtest.T) {
userCollection = mt.Coll
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/csec_mongodb_mongo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_mongodb_mongo

go 1.16
require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_robertkrimen_otto/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_robertkrimen_otto

go 1.17
require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
2 changes: 1 addition & 1 deletion instrumentation/csec_valyala_fasthttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/newrelic/csec-go-agent/instrumentation/csec_valyala_fasthttp
go 1.17

require (
github.com/newrelic/csec-go-agent v0.5.1
github.com/newrelic/csec-go-agent v0.6.0
)
4 changes: 2 additions & 2 deletions internal/security_logs/initLogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ var initLogger = DefaultLogger(true)

func init_initLogger(initlogFileName, logFilepath string, pid int) {

rotateFileHook, writer, err := NewRotateFileHook(RotateFileConfig{
rotateFileHook, writer, isDefault, _ := NewRotateFileHook(RotateFileConfig{
Filename: filepath.Join(logFilepath, initlogFileName),
Filepath: logFilepath,
MaxSize: 50, // megabytes
MaxBackups: 2,
BaseLogFilename: initlogFileName,
})

UpdateLogger(writer, "INFO", pid, initLogger, rotateFileHook, err)
UpdateLogger(writer, "INFO", pid, initLogger, rotateFileHook, isDefault)
}

func InitLogger() *logFile {
Expand Down
8 changes: 5 additions & 3 deletions internal/security_logs/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ func DefaultLogger(iscache1 bool) *logFile {

func (f *logFile) fire(level string, msg ...interface{}) {
logm := fmt.Sprintln(msg...)

if level == "ERROR" {
errLevel := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 31, "ERROR")
logm = fmt.Sprintf(" [%s] %s", errLevel, logm)
} else if level == "WARN" {
errLevel := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 33, "WARN")
logm = fmt.Sprintf(" [%s] %s", errLevel, logm)
} else {
logm = fmt.Sprintf(" [%s] %s", level, logm)
}
Expand Down Expand Up @@ -104,6 +106,6 @@ func (f *logFile) cleanCache() {
f.cache = make([]interface{}, 0)
}

func (f *logFile) IsDebug() bool{
func (f *logFile) IsDebug() bool {
return f.isDebugMode
}
}
7 changes: 4 additions & 3 deletions internal/security_logs/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ var agentLogger = DefaultLogger(false)
var isInitilized = false
var errorBuffer = secUtils.NewCring(5)

func Init(logFileName, initlogFileName, logFilepath string, pid int) {
func Init(logFileName, initlogFileName, logFilepath string, pid int) error {
isInitilized = true
rotateFileHook, writer, err := NewRotateFileHook(RotateFileConfig{
rotateFileHook, writer, isDefault, err := NewRotateFileHook(RotateFileConfig{
Filename: filepath.Join(logFilepath, logFileName),
Filepath: logFilepath,
MaxSize: 50, // megabytes
MaxBackups: 2,
BaseLogFilename: logFileName,
})

UpdateLogger(writer, "INFO", pid, agentLogger, rotateFileHook, err)
UpdateLogger(writer, "INFO", pid, agentLogger, rotateFileHook, isDefault)

init_initLogger(initlogFileName, logFilepath, pid)
return err
}

func SetLogLevel(level string) {
Expand Down
8 changes: 4 additions & 4 deletions internal/security_logs/rotateFileHook.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ func (config *RotateFileConfig) createLogDir() (io.Writer, error) {

}

func NewRotateFileHook(config RotateFileConfig) (*RotateFileHook, io.Writer, bool) {
func NewRotateFileHook(config RotateFileConfig) (*RotateFileHook, io.Writer, bool, error) {
logfile, err := config.createLogDir()
idDefault := false
isDefault := false
if err != nil {
fmt.Println(err)
logfile = os.Stdout
idDefault = true
isDefault = true
}

hook := RotateFileHook{
Config: config,
}

return &hook, logfile, idDefault
return &hook, logfile, isDefault, err
}

func (hook *RotateFileHook) Fire(logMessege, mode string, isDefault bool) string {
Expand Down
Loading

0 comments on commit 16d5280

Please sign in to comment.