Skip to content

Commit

Permalink
Merge pull request #18 from newrelic/dev
Browse files Browse the repository at this point in the history
public-apis
  • Loading branch information
prateeksen authored May 16, 2023
2 parents b62745e + 298a126 commit 7d6d35f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/newrelic_security/agent/control/reflected_xss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module ReflectedXSS

def check_xss(http_req, retval)
# TODO: Check if enableHTTPRequestPrinting is required.
return unless http_req
response_body = ::String.new
retval[2].each { |string| response_body << string }
construct = check_for_reflected_xss(http_req, retval[1], response_body)
Expand Down
1 change: 1 addition & 0 deletions lib/newrelic_security/agent/utils/agent_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def parse_fuzz_header
end

def delete_created_files
return unless NewRelic::Security::Agent::Control::HTTPContext.get_context
headers = NewRelic::Security::Agent::Control::HTTPContext.get_context.headers
if is_IAST? && is_IAST_request?(headers)
fuzz_request = headers[NR_CSEC_FUZZ_REQUEST_ID].split(COLON_IAST_COLON)
Expand Down
66 changes: 60 additions & 6 deletions lib/newrelic_security/newrelic-security-api/api.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,72 @@
module NewRelic::Security
#
# This module contains most of the public API methods for the Ruby Security Agent.
#
# @api public
#
module API
def refresh_state()

#
# Check whether security is enabled
#
# @return [Boolean] true if security is enabled else false
#
# @api public
#
def is_security_active?
NewRelic::Security::Agent.config[:'agent.enabled'] && NewRelic::Security::Agent.config[:enabled]
end

#
# Manually initializes the security agent
#
# @param [Hash] Unused options Hash
#
# @return [nil]
#
# @api public
#
def manual_start(options = {})
raise "Options must be a hash" unless Hash === options
NewRelic::Security::Agent.config.enable_security
NewRelic::Security::Agent.agent.init
end

#
# Deactivates security and stops sending events to security engine
#
# @return [nil]
#
# @api public
#
def deactivate_security
NewRelic::Security::Agent.config.disable_security
end

def send_event()
#
# Send and event to security engine
#
# @param [NewRelic::Security::Agent::Control::Event] event IAST event to be sent to validator
#
# @return [nil]
#
# @api public
#
def send_event(event)
NewRelic::Security::Agent.agent.event_processor.send_event(event)
end

def is_security_active()
end

def send_exit_event
#
# Send and exit event to security engine
#
# @param [NewRelic::Security::Agent::Control::ExitEvent] exit_event IAST exit event for api call to be sent to validator
#
# @return [nil]
#
# @api public
#
def send_exit_event(exit_event)
NewRelic::Security::Agent.agent.event_processor.send_exit_event(exit_event)
end
end
end

0 comments on commit 7d6d35f

Please sign in to comment.