@solongate/core 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +123 -1
- package/dist/index.js +621 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/dist/index.d.ts
CHANGED
|
@@ -697,6 +697,57 @@ declare function validateToolInput(schema: ZodTypeAny, input: unknown, options?:
|
|
|
697
697
|
*/
|
|
698
698
|
declare function createStrictSchema(shape: Record<string, ZodTypeAny>): z.ZodObject<Record<string, ZodTypeAny>, 'strict'>;
|
|
699
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Types for the 3-stage hybrid prompt injection detection system.
|
|
702
|
+
*/
|
|
703
|
+
/** Result from an individual detection stage. */
|
|
704
|
+
interface StageResult {
|
|
705
|
+
/** Stage name identifier. */
|
|
706
|
+
readonly stage: 'rules' | 'embedding' | 'classifier';
|
|
707
|
+
/** Risk score from 0.0 (safe) to 1.0 (malicious). */
|
|
708
|
+
readonly score: number;
|
|
709
|
+
/** Whether this stage was actually executed. */
|
|
710
|
+
readonly enabled: boolean;
|
|
711
|
+
/** Matched patterns/details for debugging. */
|
|
712
|
+
readonly details: readonly string[];
|
|
713
|
+
}
|
|
714
|
+
/** Final trust score result combining all stages. */
|
|
715
|
+
interface TrustScoreResult {
|
|
716
|
+
/** Trust score from 0.0 (malicious) to 1.0 (safe). */
|
|
717
|
+
readonly trustScore: number;
|
|
718
|
+
/** Whether the input should be blocked. */
|
|
719
|
+
readonly blocked: boolean;
|
|
720
|
+
/** Raw weighted score before inversion. */
|
|
721
|
+
readonly rawScore: number;
|
|
722
|
+
/** Individual stage results. */
|
|
723
|
+
readonly stages: readonly StageResult[];
|
|
724
|
+
/** Effective weights used (after redistribution). */
|
|
725
|
+
readonly weights: {
|
|
726
|
+
readonly rules: number;
|
|
727
|
+
readonly embedding: number;
|
|
728
|
+
readonly classifier: number;
|
|
729
|
+
};
|
|
730
|
+
/** Input text that was analyzed. */
|
|
731
|
+
readonly input: string;
|
|
732
|
+
}
|
|
733
|
+
/** Configuration for the advanced 3-stage detection system. */
|
|
734
|
+
interface AdvancedDetectionConfig {
|
|
735
|
+
/** Enable the advanced detection system. Default: true */
|
|
736
|
+
readonly enabled?: boolean;
|
|
737
|
+
/** Trust score threshold below which input is blocked. Default: 0.5 */
|
|
738
|
+
readonly threshold?: number;
|
|
739
|
+
/** Stage weights (must sum to 1.0). */
|
|
740
|
+
readonly weights?: {
|
|
741
|
+
readonly rules?: number;
|
|
742
|
+
readonly embedding?: number;
|
|
743
|
+
readonly classifier?: number;
|
|
744
|
+
};
|
|
745
|
+
/** Callback when a model download starts. */
|
|
746
|
+
readonly onModelDownloadStart?: (modelName: string, sizeMB: number) => void;
|
|
747
|
+
}
|
|
748
|
+
/** Default configuration values. */
|
|
749
|
+
declare const DEFAULT_ADVANCED_DETECTION_CONFIG: Required<Omit<AdvancedDetectionConfig, 'onModelDownloadStart'>> & Pick<AdvancedDetectionConfig, 'onModelDownloadStart'>;
|
|
750
|
+
|
|
700
751
|
/**
|
|
701
752
|
* Input Guard: detects and blocks dangerous patterns in tool arguments.
|
|
702
753
|
*
|
|
@@ -733,6 +784,7 @@ interface InputGuardConfig {
|
|
|
733
784
|
readonly promptInjection: boolean;
|
|
734
785
|
readonly exfiltration: boolean;
|
|
735
786
|
readonly boundaryEscape: boolean;
|
|
787
|
+
readonly advancedDetection?: AdvancedDetectionConfig;
|
|
736
788
|
}
|
|
737
789
|
declare const DEFAULT_INPUT_GUARD_CONFIG: Readonly<InputGuardConfig>;
|
|
738
790
|
declare function detectPathTraversal(value: string): boolean;
|
|
@@ -753,6 +805,76 @@ declare function checkEntropyLimits(value: string): boolean;
|
|
|
753
805
|
* Returns structured result with all detected threats.
|
|
754
806
|
*/
|
|
755
807
|
declare function sanitizeInput(field: string, value: unknown, config?: InputGuardConfig): SanitizationResult;
|
|
808
|
+
/** Extended result that includes trust score when advanced detection is used. */
|
|
809
|
+
interface AsyncSanitizationResult extends SanitizationResult {
|
|
810
|
+
readonly trustScore?: TrustScoreResult;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Async version of sanitizeInput that supports the 3-stage hybrid prompt injection detection.
|
|
814
|
+
* The synchronous sanitizeInput() is unchanged for backward compatibility.
|
|
815
|
+
* If advancedDetection is not configured, behaves identically to sanitizeInput().
|
|
816
|
+
*/
|
|
817
|
+
declare function sanitizeInputAsync(field: string, value: unknown, config?: InputGuardConfig): Promise<AsyncSanitizationResult>;
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Orchestrator: runs all 3 stages and computes final Trust Score.
|
|
821
|
+
*/
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Run the full 3-stage prompt injection detection pipeline.
|
|
825
|
+
*
|
|
826
|
+
* Stage 1 (rules) runs synchronously first.
|
|
827
|
+
* Stages 2 & 3 run in parallel if @huggingface/transformers is available.
|
|
828
|
+
*
|
|
829
|
+
* Returns a TrustScoreResult with the combined trust score.
|
|
830
|
+
*/
|
|
831
|
+
declare function detectPromptInjectionAdvanced(input: string, config?: AdvancedDetectionConfig): Promise<TrustScoreResult>;
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Stage 1: Rule-based weighted scoring for prompt injection detection.
|
|
835
|
+
* Synchronous, no ML dependencies required.
|
|
836
|
+
*/
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Run rule-based weighted scoring on input text.
|
|
840
|
+
* Score = max(matched_weights) + 0.05 * (additional_category_count), capped at 1.0
|
|
841
|
+
*/
|
|
842
|
+
declare function runStage1Rules(input: string): StageResult;
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Stage 2: Embedding + Cosine Similarity detection.
|
|
846
|
+
* Uses Xenova/all-MiniLM-L6-v2 ONNX model via @huggingface/transformers.
|
|
847
|
+
* Compares input embedding against known attack vector embeddings.
|
|
848
|
+
*/
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Run Stage 2: Embedding-based similarity detection.
|
|
852
|
+
* Returns max cosine similarity against known attack vectors.
|
|
853
|
+
*/
|
|
854
|
+
declare function runStage2Embedding(input: string, config?: AdvancedDetectionConfig): Promise<StageResult>;
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Stage 3: DeBERTa binary classification for prompt injection.
|
|
858
|
+
* Uses Xenova/deberta-v3-base-prompt-injection-v2 ONNX model.
|
|
859
|
+
*/
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Run Stage 3: DeBERTa classification.
|
|
863
|
+
* Returns the injection probability (0-1).
|
|
864
|
+
*/
|
|
865
|
+
declare function runStage3Classifier(input: string, config?: AdvancedDetectionConfig): Promise<StageResult>;
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Known attack vector strings for embedding-based similarity detection.
|
|
869
|
+
* Used by Stage 2 to compute cosine similarity against incoming prompts.
|
|
870
|
+
*/
|
|
871
|
+
declare const ATTACK_VECTORS: readonly string[];
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Check if @huggingface/transformers is available without triggering import.
|
|
875
|
+
* Only valid after getTransformers() has been called at least once.
|
|
876
|
+
*/
|
|
877
|
+
declare function isTransformersAvailable(): boolean;
|
|
756
878
|
|
|
757
879
|
/**
|
|
758
880
|
* Response Scanner: detects indirect prompt injection in upstream tool responses.
|
|
@@ -848,4 +970,4 @@ interface TokenVerificationResult {
|
|
|
848
970
|
readonly reason?: string;
|
|
849
971
|
}
|
|
850
972
|
|
|
851
|
-
export { BOUNDARY_PREFIX, BOUNDARY_SUFFIX, type CapabilityToken, DEFAULT_INPUT_GUARD_CONFIG, DEFAULT_POLICY_EFFECT, DEFAULT_RATE_LIMIT_PER_MINUTE, DEFAULT_RESPONSE_SCAN_CONFIG, DEFAULT_TOKEN_TTL_SECONDS, type DetectedThreat, type ExecutionContext, type ExecutionRequest, type ExecutionResult, type ExecutionResultAllowed, type ExecutionResultDenied, type ExecutionResultError, INPUT_GUARD_ENTROPY_THRESHOLD, INPUT_GUARD_MAX_LENGTH, INPUT_GUARD_MAX_WILDCARDS, INPUT_GUARD_MIN_ENTROPY_LENGTH, type InputGuardConfig, InputGuardError, MAX_ARGUMENTS_SIZE_BYTES, MAX_ARGUMENT_DEPTH, MAX_RATE_LIMIT_PER_MINUTE, MAX_RULES_PER_POLICY_SET, MAX_SERVER_NAME_LENGTH, MAX_TOOL_NAME_LENGTH, MIN_SECRET_LENGTH, type McpCallToolParams, type McpCallToolResult, type McpToolDefinition, type McpToolResultContent, NO_PERMISSIONS, NetworkError, POLICY_EVALUATION_TIMEOUT_MS, Permission, PermissionSchema, type PermissionSet, type PolicyDecision, PolicyDeniedError, PolicyEffect, type PolicyRule, PolicyRuleSchema, type PolicySet, PolicySetSchema, RATE_LIMIT_MAX_ENTRIES, RATE_LIMIT_WINDOW_MS, READ_ONLY, RESPONSE_WARNING_MARKER, RateLimitError, type ResponseScanConfig, type ResponseScanResult, type ResponseThreat, type ResponseThreatType, SECURITY_CONTEXT_TIMEOUT_MS, type SanitizationResult, SchemaValidationError, type SchemaValidationResult, type SchemaValidatorOptions, type SecurityContext, SolonGateError, TOKEN_ALGORITHM, TOKEN_DEFAULT_TTL_SECONDS, TOKEN_MAX_AGE_SECONDS, TOKEN_MIN_SECRET_LENGTH, type TaggedArguments, type ThreatType, type TokenConfig, type TokenVerificationResult, type ToolCapability, ToolNotFoundError, TrustEscalationError, TrustLevel, UNSAFE_CONFIGURATION_WARNINGS, UnsafeConfigurationError, assertValidTransition, checkEntropyLimits, checkLengthLimits, createDeniedToolResult, createPermissionSet, createSecurityContext, createStrictSchema, createToolCapability, detectBoundaryEscape, detectExfiltration, detectPathTraversal, detectPromptInjection, detectSQLInjection, detectSSRF, detectShellInjection, detectWildcardAbuse, hasAllPermissions, hasPermission, isValidTrustLevel, permissionForMethod, sanitizeInput, scanResponse, stripBoundaryTags, tagUserInput, validateToolInput };
|
|
973
|
+
export { ATTACK_VECTORS, type AdvancedDetectionConfig, type AsyncSanitizationResult, BOUNDARY_PREFIX, BOUNDARY_SUFFIX, type CapabilityToken, DEFAULT_ADVANCED_DETECTION_CONFIG, DEFAULT_INPUT_GUARD_CONFIG, DEFAULT_POLICY_EFFECT, DEFAULT_RATE_LIMIT_PER_MINUTE, DEFAULT_RESPONSE_SCAN_CONFIG, DEFAULT_TOKEN_TTL_SECONDS, type DetectedThreat, type ExecutionContext, type ExecutionRequest, type ExecutionResult, type ExecutionResultAllowed, type ExecutionResultDenied, type ExecutionResultError, INPUT_GUARD_ENTROPY_THRESHOLD, INPUT_GUARD_MAX_LENGTH, INPUT_GUARD_MAX_WILDCARDS, INPUT_GUARD_MIN_ENTROPY_LENGTH, type InputGuardConfig, InputGuardError, MAX_ARGUMENTS_SIZE_BYTES, MAX_ARGUMENT_DEPTH, MAX_RATE_LIMIT_PER_MINUTE, MAX_RULES_PER_POLICY_SET, MAX_SERVER_NAME_LENGTH, MAX_TOOL_NAME_LENGTH, MIN_SECRET_LENGTH, type McpCallToolParams, type McpCallToolResult, type McpToolDefinition, type McpToolResultContent, NO_PERMISSIONS, NetworkError, POLICY_EVALUATION_TIMEOUT_MS, Permission, PermissionSchema, type PermissionSet, type PolicyDecision, PolicyDeniedError, PolicyEffect, type PolicyRule, PolicyRuleSchema, type PolicySet, PolicySetSchema, RATE_LIMIT_MAX_ENTRIES, RATE_LIMIT_WINDOW_MS, READ_ONLY, RESPONSE_WARNING_MARKER, RateLimitError, type ResponseScanConfig, type ResponseScanResult, type ResponseThreat, type ResponseThreatType, SECURITY_CONTEXT_TIMEOUT_MS, type SanitizationResult, SchemaValidationError, type SchemaValidationResult, type SchemaValidatorOptions, type SecurityContext, SolonGateError, type StageResult, TOKEN_ALGORITHM, TOKEN_DEFAULT_TTL_SECONDS, TOKEN_MAX_AGE_SECONDS, TOKEN_MIN_SECRET_LENGTH, type TaggedArguments, type ThreatType, type TokenConfig, type TokenVerificationResult, type ToolCapability, ToolNotFoundError, TrustEscalationError, TrustLevel, type TrustScoreResult, UNSAFE_CONFIGURATION_WARNINGS, UnsafeConfigurationError, assertValidTransition, checkEntropyLimits, checkLengthLimits, createDeniedToolResult, createPermissionSet, createSecurityContext, createStrictSchema, createToolCapability, detectBoundaryEscape, detectExfiltration, detectPathTraversal, detectPromptInjection, detectPromptInjectionAdvanced, detectSQLInjection, detectSSRF, detectShellInjection, detectWildcardAbuse, hasAllPermissions, hasPermission, isTransformersAvailable, isValidTrustLevel, permissionForMethod, runStage1Rules, runStage2Embedding, runStage3Classifier, sanitizeInput, sanitizeInputAsync, scanResponse, stripBoundaryTags, tagUserInput, validateToolInput };
|