Skip to content

Commit

Permalink
Add mode to operation READ/WRITE/DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
lovesh-ap committed Nov 1, 2023
1 parent 53a01b7 commit 6a9bed3
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ private JavaAgentEventBean prepareCachingDataStoreEvent(JavaAgentEventBean event
command.put(REDIS_MODE, redisOperation.getMode());
command.put(REDIS_ARGUMENTS, params);
command.put(REDIS_TYPE, redisOperation.getType());
eventBean.setParameters(params);
JSONArray parameter = new JSONArray();
parameter.add(command);
eventBean.setParameters(parameter);
return eventBean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package com.newrelic.api.agent.security.schema.helper;

import java.util.Arrays;
import java.util.List;

public class RedisCommands {

public static final List<String> readCommands = Arrays.asList(
"ACL",
"BITCOUNT",
"BITPO",
"CONFIG",
"DBSIZE",
"DUMP",
"ECHO",
"EVAL",
"EVAL_RO",
"EVALSHA",
"EVALSHA_RO",
"EXISTS",
"EXPIRETIME",
"GEODIST",
"GEOHASH",
"GEOPOS",
"GEORADIUS",
"GEORADIUS_RO",
"GEORADIUSBYMEMBER",
"GEORADIUSBYMEMBER_RO",
"GEOSEARCH",
"GET",
"GETBIT",
"GETDEL",
"GETEX",
"GETRANGE",
"GETSET",
"HEXISTS",
"HGET",
"HGETALL",
"HKEYS",
"HLEN",
"HMGET",
"HRANDFIELD",
"HSCAN",
"HSTRLEN",
"HVALS",
"INFO",
"KEYS",
"LINDEX",
"LLEN",
"LPOS",
"LRANGE",
"MEMORY",
"MGET",
"MODULE LIST",
"OBJECT",
"PFCOUNT",
"PTTL",
"RANDOMKEY",
"SCAN",
"SCARD",
"SCRIPT",
"SDIFF",
"SDIFFSTORE",
"SINTER",
"SINTERCARD",
"SINTERSTORE",
"SISMEMBER",
"SLOWLOG",
"SMEMBERS",
"SMISMEMBER",
"SORT",
"SORT_RO",
"SRANDMEMBER",
"SSCAN",
"STRLEN",
"SUNION",
"SUNIONSTORE",
"TOUCH",
"TTL",
"TYPE",
"XACK",
"XINFO",
"XLEN",
"XPENDING",
"XRANGE",
"XREAD",
"XREADGROUP",
"XREVRANGE",
"ZCARD",
"ZCOUNT",
"ZDIFF",
"ZDIFFSTORE",
"ZINTER",
"ZINTERCARD",
"ZLEXCOUNT",
"ZMSCORE",
"ZRANDMEMBER",
"ZRANGE",
"ZRANGEBYLEX",
"ZRANGEBYSCORE",
"ZRANGESTORE",
"ZRANK",
"ZREVRANGE",
"ZREVRANGEBYLEX",
"ZREVRANGEBYSCORE",
"ZREVRANK",
"ZSCAN",
"ZSCORE",
"ZUNION",
"ZUNIONSTORE"
);

public static final List<String> writeCommands = Arrays.asList(
"ACL",
"APPEND",
"BITPOS",
"BGREWRITEAOF",
"BITFIELD",
"BITOP",
"BLMOVE",
"BRPOPLPUSH",
"CONFIG",
"COPY",
"DECR",
"DECRBY",
"EVAL",
"EVALSHA",
"EXPIRE",
"EXPIREAT",
"GEOADD",
"GEOSEARCHSTORE",
"GETEX",
"GETSET",
"HINCRBY",
"HINCRBYFLOAT",
"HMSET",
"HSET",
"HSETNX",
"INCR",
"INCRBY",
"INCRBYFLOAT",
"LINSERT",
"LMOVE",
"LPUSH",
"LPUSHX",
"LSET",
"MIGRATE",
"MOVE",
"MSET",
"MSETNX",
"PERSIST",
"PEXPIRE",
"PEXPIREAT",
"PEXPIRETIME",
"PFADD",
"PFMERGE",
"PSETEX",
"RENAME",
"RENAMENX",
"RESTORE",
"RPOPLPUSH",
"RPUSH",
"RPUSHX",
"SADD",
"SCRIPT DEBUG",
"SDIFFSTORE",
"SET",
"SETEX",
"SETBIT",
"SETNX",
"SETRANGE",
"SINTERSTORE",
"SMOVE",
"SUNIONSTORE",
"SWAPDB",
"XADD",
"XAUTOCLAIM",
"XCLAIM",
"XGROUP",
"ZADD",
"ZDIFFSTORE",
"ZINCRBY",
"ZINTERSTORE",
"ZRANGESTORE",
"ZUNIONSTORE"
);

public static final List<String> deleteCommands = Arrays.asList(
"ACL",
"BLMPOP",
"BLPOP",
"BRPOP",
"BRPOPLPUSH",
"BZPOPMAX",
"BZPOPMIN",
"DEL",
"DISCARD",
"EVAL",
"EVALSHA",
"FLUSHALL",
"FLUSHDB",
"GETDEL",
"HDEL",
"LMPOP",
"LPOP",
"LREM",
"MEMORY",
"RPOP",
"RPOPLPUSH",
"SCRIPT",
"SLOWLOG",
"SPOP",
"SREM",
"UNLINK",
"LTRIM",
"XDEL",
"XGROUP ",
"XTRIM",
"ZPOPMAX",
"ZPOPMIN",
"ZREM",
"ZREMRANGEBYLEX",
"ZREMRANGEBYRANK",
"ZREMRANGEBYSCORE"
);

public static final String READ_COMMAND = "READ";
public static final String WRITE_COMMAND = "WRITE";
public static final String DELETE_COMMAND = "DELETE" ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.security.schema.helper.RedisCommands;

import java.util.List;

Expand All @@ -21,6 +22,17 @@ public RedisOperation(String className, String methodName, String type, List<Obj
this.category = REDIS;
this.type = type;
this.arguments = arguments;
this.mode = getMode(type);
}

private String getMode(String type) {
if(RedisCommands.writeCommands.contains(type)){
return RedisCommands.WRITE_COMMAND;
} else if (RedisCommands.deleteCommands.contains(type)) {
return RedisCommands.DELETE_COMMAND;
} else {
return RedisCommands.READ_COMMAND;
}
}

public String getType() {
Expand Down

0 comments on commit 6a9bed3

Please sign in to comment.