Class: Rack::AI::Features::Security
- Inherits:
-
Object
- Object
- Rack::AI::Features::Security
- Defined in:
- lib/rack/ai/features/security.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(provider, config) ⇒ Security
constructor
A new instance of Security.
- #process_request(env) ⇒ Object
- #process_response? ⇒ Boolean
Constructor Details
#initialize(provider, config) ⇒ Security
9 10 11 12 13 |
# File 'lib/rack/ai/features/security.rb', line 9 def initialize(provider, config) @name = :security @provider = provider @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/rack/ai/features/security.rb', line 7 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rack/ai/features/security.rb', line 7 def name @name end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/rack/ai/features/security.rb', line 7 def provider @provider end |
Instance Method Details
#enabled? ⇒ Boolean
15 16 17 |
# File 'lib/rack/ai/features/security.rb', line 15 def enabled? @config.feature_enabled?(:security) end |
#process_request(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rack/ai/features/security.rb', line 23 def process_request(env) request_data = @provider.build_request_data(env) # Detect various security threats anomaly_result = @provider.detect_anomalies(request_data) injection_result = detect_injection_attacks(env) rate_limit_result = check_rate_limiting(env) # Combine all security checks threat_level = determine_overall_threat_level([ anomaly_result[:threat_level], injection_result[:threat_level], rate_limit_result[:threat_level] ]) result = { threat_level: threat_level, anomaly_detection: anomaly_result, injection_detection: injection_result, rate_limiting: rate_limit_result, action: determine_security_action(threat_level), feature: @name, timestamp: Time.now.iso8601 } # Add detailed security metadata result[:security_headers] = analyze_security_headers(env) result[:suspicious_patterns] = identify_suspicious_patterns(env) result end |
#process_response? ⇒ Boolean
19 20 21 |
# File 'lib/rack/ai/features/security.rb', line 19 def process_response? false end |