Skip to content

Class SecurityConfiguration

Namespace: Belay.Core.Security
Assembly: Belay.Core.dll

Configuration options for security validation and protection features in Belay.NET. Controls the strictness of input validation, code injection protection, and other security measures.

csharp
public class SecurityConfiguration

Inheritance

objectSecurityConfiguration

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Examples

Basic Security Configuration

var config = new SecurityConfiguration {
    ValidationLevel = ValidationStrictness.Strict,
    AllowFileOperations = true,
    AllowNetworking = false,
    LogSecurityEvents = true
};

var device = Device.FromConnectionString("serial:COM3")
    .WithSecurityConfiguration(config);

Development Environment (Relaxed)

var devConfig = SecurityConfiguration.ForDevelopment();
var device = Device.FromConnectionString("subprocess:micropython")
    .WithSecurityConfiguration(devConfig);

Production Environment (Strict)

var prodConfig = SecurityConfiguration.ForProduction();
var device = Device.FromConnectionString("serial:/dev/ttyUSB0")
    .WithSecurityConfiguration(prodConfig);

Remarks

The security configuration allows fine-tuning the balance between security and functionality. More restrictive settings provide better protection but may prevent legitimate use cases, while more permissive settings enable broader functionality but with increased risk.

Configuration can be applied at the device level or globally, with device-specific settings taking precedence over global settings.

Properties

AllowFileOperations

Gets or sets a value indicating whether file operations are allowed in executed code.

AllowNetworking

Gets or sets a value indicating whether networking operations are allowed in executed code.

CustomAllowedPatterns

Gets or sets custom patterns that should be allowed even if they would normally be blocked.

CustomBlockedPatterns

Gets or sets custom patterns that should be blocked in addition to the default security patterns.

LogSecurityEvents

Gets or sets a value indicating whether to log security-related events and warnings.

MaxCodeLength

Gets or sets the maximum allowed length for Python code before it's considered a security risk.

MaxNestingLevel

Gets or sets the maximum allowed nesting level for code structures before triggering security warnings.

ValidateParameterSubstitution

Gets or sets a value indicating whether parameter substitution in PythonCodeAttribute should be validated.

ValidationLevel

Gets or sets the level of strictness for input validation.

Methods

Clone()

Creates a copy of the current configuration.

ForDevelopment()

Creates a security configuration suitable for development environments.

ForProduction()

Creates a security configuration suitable for production environments.

ForTesting()

Creates a security configuration suitable for testing environments.

Released under the Apache License 2.0.