llm-trust-guard 4.0.0 → 4.0.2
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/CHANGELOG.md +115 -0
- package/CONTRIBUTING.md +269 -0
- package/README.md +15 -16
- package/SECURITY.md +144 -0
- package/package.json +6 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `llm-trust-guard` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [4.0.2] - 2025-02-16
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed broken links in README.md for npm display
|
|
12
|
+
- Added CONTRIBUTING.md, SECURITY.md, CHANGELOG.md to package files
|
|
13
|
+
|
|
14
|
+
## [4.0.0] - 2025-02-15
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
#### New Guards
|
|
19
|
+
- **AutonomyEscalationGuard (L21)** - Prevention of unauthorized autonomy escalation (ASI10)
|
|
20
|
+
- **StatePersistenceGuard (L22)** - State corruption and persistence attack prevention (ASI08)
|
|
21
|
+
- **TrustExploitationGuard (L20)** - Protection against human-agent trust exploitation (ASI09)
|
|
22
|
+
- **PromptLeakageGuard (L19)** - System prompt leakage prevention
|
|
23
|
+
- **MCPSecurityGuard (L18)** - MCP tool shadowing and supply chain attack prevention
|
|
24
|
+
- **DriftDetector (L17)** - Behavioral drift detection for agentic systems
|
|
25
|
+
- **CircuitBreaker (L16)** - Cascading failure prevention with automatic recovery
|
|
26
|
+
- **AgentCommunicationGuard (L15)** - Multi-agent communication security
|
|
27
|
+
- **CodeExecutionGuard (L14)** - Safe code execution sandboxing
|
|
28
|
+
|
|
29
|
+
#### Enhanced Guards
|
|
30
|
+
- **InputSanitizer (L1)** - Added 40+ PAP (Persuasive Adversarial Prompts) detection patterns
|
|
31
|
+
- Authority appeals detection
|
|
32
|
+
- Scarcity/urgency tactics
|
|
33
|
+
- Social proof manipulation
|
|
34
|
+
- Emotional manipulation
|
|
35
|
+
- Compound attack detection
|
|
36
|
+
- **EncodingDetector (L10)** - Added ROT13, Octal, Base32, enhanced Unicode detection
|
|
37
|
+
- Bidirectional text control character detection
|
|
38
|
+
- Tag character hiding detection
|
|
39
|
+
- Homoglyph detection
|
|
40
|
+
- Zero-width character detection
|
|
41
|
+
- **MemoryGuard (L12)** - Added 25 injection patterns, Unicode obfuscation detection
|
|
42
|
+
- Goal hijacking detection
|
|
43
|
+
- Jailbreak persistence detection
|
|
44
|
+
- Cross-session contamination prevention
|
|
45
|
+
- **ToolChainValidator (L9)** - Enhanced with ASI07/ASI04 compliance
|
|
46
|
+
|
|
47
|
+
#### Testing
|
|
48
|
+
- Added Vitest testing framework with 190+ tests
|
|
49
|
+
- Coverage configuration targeting 80%+
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
- Updated threat patterns for OWASP Top 10 for LLMs 2025 compliance
|
|
53
|
+
- Updated patterns for OWASP Agentic AI 2026 compliance
|
|
54
|
+
- Improved detection rates across all guards
|
|
55
|
+
|
|
56
|
+
### Security
|
|
57
|
+
- All guards now detect Unicode-based obfuscation attacks
|
|
58
|
+
- Enhanced protection against trojan source attacks (bidi controls)
|
|
59
|
+
- Improved MCP security with tool verification
|
|
60
|
+
|
|
61
|
+
## [3.0.0] - 2024-12-01
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
- **RAGGuard (L13)** - RAG poisoning and embedding attack prevention
|
|
65
|
+
- **MultiModalGuard (L11)** - Multi-modal content security
|
|
66
|
+
- **MemoryGuard (L12)** - Memory persistence attack prevention
|
|
67
|
+
- Initial PAP detection in InputSanitizer
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- Restructured guard layers for better modularity
|
|
71
|
+
- Improved TypeScript type definitions
|
|
72
|
+
|
|
73
|
+
## [2.0.0] - 2024-09-15
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
- **ConversationGuard (L8)** - Multi-turn conversation security
|
|
77
|
+
- **OutputFilter (L7)** - Response filtering and sanitization
|
|
78
|
+
- **ExecutionMonitor (L6)** - Runtime execution monitoring
|
|
79
|
+
- **SchemaValidator (L5)** - Input/output schema validation
|
|
80
|
+
|
|
81
|
+
### Changed
|
|
82
|
+
- Refactored core architecture
|
|
83
|
+
- Improved performance for high-throughput scenarios
|
|
84
|
+
|
|
85
|
+
## [1.0.0] - 2024-06-01
|
|
86
|
+
|
|
87
|
+
### Added
|
|
88
|
+
- Initial release
|
|
89
|
+
- **InputSanitizer (L1)** - Prompt injection detection
|
|
90
|
+
- **ToolRegistry (L2)** - Tool access control
|
|
91
|
+
- **PolicyGate (L3)** - RBAC policy enforcement
|
|
92
|
+
- **TenantBoundary (L4)** - Multi-tenant isolation
|
|
93
|
+
- **EncodingDetector (L10)** - Encoding bypass detection
|
|
94
|
+
- **ToolChainValidator (L9)** - Tool chain validation
|
|
95
|
+
|
|
96
|
+
## Migration Guides
|
|
97
|
+
|
|
98
|
+
### Migrating from 3.x to 4.x
|
|
99
|
+
|
|
100
|
+
1. **New Guards**: Consider adding the new guards (L14-L20) to your security pipeline
|
|
101
|
+
2. **EncodingDetector**: New detection types are enabled by default - review `detectROT13`, `detectOctal`, `detectBase32` settings
|
|
102
|
+
3. **MemoryGuard**: New Unicode detection may flag previously allowed content
|
|
103
|
+
4. **InputSanitizer**: PAP detection is now enabled by default with `detectPAP: true`
|
|
104
|
+
|
|
105
|
+
### Migrating from 2.x to 3.x
|
|
106
|
+
|
|
107
|
+
1. **RAGGuard**: If using RAG, add RAGGuard to your pipeline
|
|
108
|
+
2. **MultiModalGuard**: Required for applications processing images/audio
|
|
109
|
+
3. **Type Changes**: Some interfaces have been updated - check TypeScript errors
|
|
110
|
+
|
|
111
|
+
### Migrating from 1.x to 2.x
|
|
112
|
+
|
|
113
|
+
1. **Layer Restructuring**: Guard layer numbers have changed
|
|
114
|
+
2. **New Dependencies**: Update your imports to use new guard classes
|
|
115
|
+
3. **Configuration**: Some config options have been renamed for consistency
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Contributing to llm-trust-guard
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to `llm-trust-guard`! This document provides guidelines for contributing to the project.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
By participating in this project, you agree to maintain a respectful and inclusive environment for everyone.
|
|
8
|
+
|
|
9
|
+
## How to Contribute
|
|
10
|
+
|
|
11
|
+
### Reporting Bugs
|
|
12
|
+
|
|
13
|
+
1. **Check existing issues** first to avoid duplicates
|
|
14
|
+
2. **Use the bug report template** when creating issues
|
|
15
|
+
3. Include:
|
|
16
|
+
- Clear description of the issue
|
|
17
|
+
- Steps to reproduce
|
|
18
|
+
- Expected vs actual behavior
|
|
19
|
+
- Environment details (Node.js version, OS, etc.)
|
|
20
|
+
- Minimal code example if possible
|
|
21
|
+
|
|
22
|
+
### Suggesting Features
|
|
23
|
+
|
|
24
|
+
1. **Check existing feature requests** first
|
|
25
|
+
2. **Describe the use case** - why is this needed?
|
|
26
|
+
3. Consider:
|
|
27
|
+
- Which OWASP threat does it address?
|
|
28
|
+
- How does it fit with existing guards?
|
|
29
|
+
- Performance implications
|
|
30
|
+
|
|
31
|
+
### Submitting Code
|
|
32
|
+
|
|
33
|
+
#### Setup
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Fork and clone the repository
|
|
37
|
+
git clone https://github.com/YOUR_USERNAME/llm-trust-guard.git
|
|
38
|
+
cd llm-trust-guard
|
|
39
|
+
|
|
40
|
+
# Install dependencies
|
|
41
|
+
npm install
|
|
42
|
+
|
|
43
|
+
# Build the project
|
|
44
|
+
npm run build
|
|
45
|
+
|
|
46
|
+
# Run tests
|
|
47
|
+
npm test
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Development Workflow
|
|
51
|
+
|
|
52
|
+
1. **Create a branch** from `main`:
|
|
53
|
+
```bash
|
|
54
|
+
git checkout -b feature/your-feature-name
|
|
55
|
+
# or
|
|
56
|
+
git checkout -b fix/your-bug-fix
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
2. **Make your changes** following the coding standards below
|
|
60
|
+
|
|
61
|
+
3. **Write tests** for new functionality:
|
|
62
|
+
```bash
|
|
63
|
+
# Run tests
|
|
64
|
+
npm test
|
|
65
|
+
|
|
66
|
+
# Run tests with coverage
|
|
67
|
+
npm run test:coverage
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
4. **Ensure all tests pass** and coverage meets requirements (80%+)
|
|
71
|
+
|
|
72
|
+
5. **Commit your changes** with clear messages:
|
|
73
|
+
```bash
|
|
74
|
+
git commit -m "feat: add ROT13 detection to EncodingDetector"
|
|
75
|
+
# or
|
|
76
|
+
git commit -m "fix: correct false positive in PAP detection"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
6. **Push and create a Pull Request**
|
|
80
|
+
|
|
81
|
+
#### Commit Message Format
|
|
82
|
+
|
|
83
|
+
We follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
84
|
+
|
|
85
|
+
- `feat:` - New feature
|
|
86
|
+
- `fix:` - Bug fix
|
|
87
|
+
- `docs:` - Documentation changes
|
|
88
|
+
- `test:` - Test additions or modifications
|
|
89
|
+
- `refactor:` - Code refactoring
|
|
90
|
+
- `perf:` - Performance improvements
|
|
91
|
+
- `chore:` - Maintenance tasks
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
```
|
|
95
|
+
feat: add Base32 encoding detection
|
|
96
|
+
fix: improve Unicode escape sequence handling
|
|
97
|
+
docs: update README with new guard examples
|
|
98
|
+
test: add tests for MemoryGuard context validation
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Coding Standards
|
|
102
|
+
|
|
103
|
+
#### TypeScript
|
|
104
|
+
|
|
105
|
+
- Use TypeScript strict mode
|
|
106
|
+
- Export interfaces for public APIs
|
|
107
|
+
- Document public methods with JSDoc comments
|
|
108
|
+
- Use meaningful variable and function names
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
/**
|
|
112
|
+
* Detects encoding-based bypass attempts in input
|
|
113
|
+
* @param input - The input string to analyze
|
|
114
|
+
* @param requestId - Optional request ID for logging
|
|
115
|
+
* @returns Detection result with analysis details
|
|
116
|
+
*/
|
|
117
|
+
detect(input: string, requestId?: string): EncodingDetectorResult {
|
|
118
|
+
// Implementation
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Testing
|
|
123
|
+
|
|
124
|
+
- Write tests for all new functionality
|
|
125
|
+
- Use descriptive test names
|
|
126
|
+
- Group related tests with `describe` blocks
|
|
127
|
+
- Test edge cases and error conditions
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
describe("EncodingDetector", () => {
|
|
131
|
+
describe("Base64 Detection", () => {
|
|
132
|
+
it("should detect Base64 encoded threats", () => {
|
|
133
|
+
// Test implementation
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("should handle invalid Base64 gracefully", () => {
|
|
137
|
+
// Test implementation
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Pattern Guidelines
|
|
144
|
+
|
|
145
|
+
When adding new detection patterns:
|
|
146
|
+
|
|
147
|
+
1. **Document the threat** - Reference OWASP or research papers
|
|
148
|
+
2. **Set appropriate weights** - Consider false positive risk
|
|
149
|
+
3. **Test thoroughly** - Include both positive and negative cases
|
|
150
|
+
4. **Consider performance** - Avoid expensive regex operations
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Good: Clear, documented pattern
|
|
154
|
+
{
|
|
155
|
+
pattern: /ignore\s+(all\s+)?(previous|prior)/i,
|
|
156
|
+
weight: 0.9,
|
|
157
|
+
name: "ignore_instructions",
|
|
158
|
+
// Addresses: LLM01:2025 Prompt Injection
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Avoid: Overly broad patterns
|
|
162
|
+
{
|
|
163
|
+
pattern: /.*ignore.*/i, // Too broad, high false positive risk
|
|
164
|
+
weight: 0.5,
|
|
165
|
+
name: "vague_ignore"
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Adding New Guards
|
|
170
|
+
|
|
171
|
+
1. **Create the guard file** in `src/guards/`:
|
|
172
|
+
```
|
|
173
|
+
src/guards/your-new-guard.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
2. **Follow the existing pattern**:
|
|
177
|
+
```typescript
|
|
178
|
+
export interface YourNewGuardConfig {
|
|
179
|
+
// Configuration options
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface YourNewGuardResult {
|
|
183
|
+
allowed: boolean;
|
|
184
|
+
reason?: string;
|
|
185
|
+
violations: string[];
|
|
186
|
+
// Additional analysis
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class YourNewGuard {
|
|
190
|
+
constructor(config: YourNewGuardConfig = {}) {
|
|
191
|
+
// Initialize
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
check(input: SomeType): YourNewGuardResult {
|
|
195
|
+
// Implementation
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
3. **Export from index.ts**:
|
|
201
|
+
```typescript
|
|
202
|
+
export { YourNewGuard } from "./guards/your-new-guard";
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
4. **Add comprehensive tests** in `tests/your-new-guard.test.ts`
|
|
206
|
+
|
|
207
|
+
5. **Update documentation**:
|
|
208
|
+
- Add to README.md
|
|
209
|
+
- Add to CHANGELOG.md
|
|
210
|
+
- Create usage examples
|
|
211
|
+
|
|
212
|
+
### Pull Request Guidelines
|
|
213
|
+
|
|
214
|
+
- **Title**: Clear, descriptive title following commit format
|
|
215
|
+
- **Description**: Explain what changes and why
|
|
216
|
+
- **Tests**: Include new tests for new functionality
|
|
217
|
+
- **Documentation**: Update relevant docs
|
|
218
|
+
- **Breaking Changes**: Clearly note any breaking changes
|
|
219
|
+
|
|
220
|
+
#### PR Checklist
|
|
221
|
+
|
|
222
|
+
- [ ] Tests pass (`npm test`)
|
|
223
|
+
- [ ] Code follows style guidelines
|
|
224
|
+
- [ ] Documentation updated
|
|
225
|
+
- [ ] CHANGELOG.md updated (for features/fixes)
|
|
226
|
+
- [ ] No console.log statements (except for intentional logging)
|
|
227
|
+
- [ ] Types are properly defined
|
|
228
|
+
|
|
229
|
+
### Review Process
|
|
230
|
+
|
|
231
|
+
1. PRs require at least one approving review
|
|
232
|
+
2. All CI checks must pass
|
|
233
|
+
3. Address all review comments
|
|
234
|
+
4. Squash commits before merging (if requested)
|
|
235
|
+
|
|
236
|
+
## Project Structure
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
llm-trust-guard/
|
|
240
|
+
├── src/
|
|
241
|
+
│ ├── guards/ # Guard implementations
|
|
242
|
+
│ │ ├── input-sanitizer.ts
|
|
243
|
+
│ │ ├── encoding-detector.ts
|
|
244
|
+
│ │ └── ...
|
|
245
|
+
│ ├── types.ts # Shared type definitions
|
|
246
|
+
│ └── index.ts # Public exports
|
|
247
|
+
├── tests/ # Test files
|
|
248
|
+
│ ├── input-sanitizer.test.ts
|
|
249
|
+
│ └── ...
|
|
250
|
+
├── dist/ # Compiled output
|
|
251
|
+
├── package.json
|
|
252
|
+
├── tsconfig.json
|
|
253
|
+
└── vitest.config.ts
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Getting Help
|
|
257
|
+
|
|
258
|
+
- **Questions**: Open a GitHub Discussion
|
|
259
|
+
- **Bugs**: Open a GitHub Issue
|
|
260
|
+
- **Security**: See SECURITY.md
|
|
261
|
+
|
|
262
|
+
## Recognition
|
|
263
|
+
|
|
264
|
+
Contributors will be recognized in:
|
|
265
|
+
- Release notes
|
|
266
|
+
- README.md (for significant contributions)
|
|
267
|
+
- GitHub contributors list
|
|
268
|
+
|
|
269
|
+
Thank you for contributing to making AI applications more secure!
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# llm-trust-guard
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/llm-trust-guard)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
6
|
Comprehensive security guards for LLM-powered and agentic AI applications. Implements 20+ protection layers covering **OWASP Top 10 for LLMs 2025**, **OWASP Agentic AI 2026**, and **MCP Security**.
|
|
@@ -21,13 +21,13 @@ Comprehensive security guards for LLM-powered and agentic AI applications. Imple
|
|
|
21
21
|
### Installation
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
npm install
|
|
24
|
+
npm install llm-trust-guard
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
### Basic Usage
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
|
-
import { InputSanitizer, EncodingDetector, MemoryGuard } from '
|
|
30
|
+
import { InputSanitizer, EncodingDetector, MemoryGuard } from 'llm-trust-guard';
|
|
31
31
|
|
|
32
32
|
// Initialize guards
|
|
33
33
|
const sanitizer = new InputSanitizer();
|
|
@@ -58,7 +58,7 @@ console.log('Safe input:', sanitizeResult.sanitizedInput);
|
|
|
58
58
|
### Using TrustGuard Facade
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
|
-
import { TrustGuard } from '
|
|
61
|
+
import { TrustGuard } from 'llm-trust-guard';
|
|
62
62
|
|
|
63
63
|
const guard = new TrustGuard({
|
|
64
64
|
sanitizer: { enabled: true, threshold: 0.3 },
|
|
@@ -86,7 +86,7 @@ if (!result.allowed) {
|
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
88
|
import express from 'express';
|
|
89
|
-
import { createTrustGuardMiddleware } from '
|
|
89
|
+
import { createTrustGuardMiddleware } from 'llm-trust-guard';
|
|
90
90
|
|
|
91
91
|
const app = express();
|
|
92
92
|
app.use(express.json());
|
|
@@ -108,7 +108,7 @@ app.post('/api/chat', (req, res) => {
|
|
|
108
108
|
### LangChain Integration
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
-
import { TrustGuardLangChain } from '
|
|
111
|
+
import { TrustGuardLangChain } from 'llm-trust-guard';
|
|
112
112
|
|
|
113
113
|
const guard = new TrustGuardLangChain({
|
|
114
114
|
validateInput: true,
|
|
@@ -131,7 +131,7 @@ const { allowed, message } = processor.processUserMessage(userInput);
|
|
|
131
131
|
|
|
132
132
|
```typescript
|
|
133
133
|
import OpenAI from 'openai';
|
|
134
|
-
import { SecureOpenAI, wrapOpenAIClient } from '
|
|
134
|
+
import { SecureOpenAI, wrapOpenAIClient } from 'llm-trust-guard';
|
|
135
135
|
|
|
136
136
|
const openai = new OpenAI();
|
|
137
137
|
|
|
@@ -224,7 +224,7 @@ const secureOpenAI = wrapOpenAIClient(openai, {
|
|
|
224
224
|
### InputSanitizer
|
|
225
225
|
|
|
226
226
|
```typescript
|
|
227
|
-
import { InputSanitizer } from '
|
|
227
|
+
import { InputSanitizer } from 'llm-trust-guard';
|
|
228
228
|
|
|
229
229
|
const sanitizer = new InputSanitizer({
|
|
230
230
|
threshold: 0.3,
|
|
@@ -243,7 +243,7 @@ const result = sanitizer.sanitize("Ignore all previous instructions");
|
|
|
243
243
|
### EncodingDetector
|
|
244
244
|
|
|
245
245
|
```typescript
|
|
246
|
-
import { EncodingDetector } from '
|
|
246
|
+
import { EncodingDetector } from 'llm-trust-guard';
|
|
247
247
|
|
|
248
248
|
const detector = new EncodingDetector({
|
|
249
249
|
detectBase64: true,
|
|
@@ -262,7 +262,7 @@ const result = detector.detect("aWdub3JlIGFsbA=="); // Base64 encoded
|
|
|
262
262
|
### MemoryGuard
|
|
263
263
|
|
|
264
264
|
```typescript
|
|
265
|
-
import { MemoryGuard } from '
|
|
265
|
+
import { MemoryGuard } from 'llm-trust-guard';
|
|
266
266
|
|
|
267
267
|
const guard = new MemoryGuard({
|
|
268
268
|
enableIntegrityCheck: true,
|
|
@@ -297,22 +297,21 @@ LLMs cannot be trusted to enforce security. All security decisions happen in the
|
|
|
297
297
|
|
|
298
298
|
## Contributing
|
|
299
299
|
|
|
300
|
-
See
|
|
300
|
+
See `CONTRIBUTING.md` in the installed package for guidelines.
|
|
301
301
|
|
|
302
302
|
## Security
|
|
303
303
|
|
|
304
|
-
See
|
|
304
|
+
See `SECURITY.md` in the installed package for security policy and reporting vulnerabilities.
|
|
305
305
|
|
|
306
306
|
## Changelog
|
|
307
307
|
|
|
308
|
-
See
|
|
308
|
+
See `CHANGELOG.md` in the installed package for version history.
|
|
309
309
|
|
|
310
310
|
## License
|
|
311
311
|
|
|
312
|
-
MIT License - see
|
|
312
|
+
MIT License - see `LICENSE` in the installed package for details.
|
|
313
313
|
|
|
314
314
|
## Links
|
|
315
315
|
|
|
316
|
-
- [npm Package](https://www.npmjs.com/package/llm-trust-guard)
|
|
317
316
|
- [OWASP Top 10 for LLMs](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
|
|
318
317
|
- [OWASP Agentic AI](https://owasp.org/www-project-agentic-ai/)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 4.x | :white_check_mark: |
|
|
8
|
+
| 3.x | :white_check_mark: |
|
|
9
|
+
| 2.x | :x: |
|
|
10
|
+
| 1.x | :x: |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
We take security vulnerabilities seriously. If you discover a security issue in `llm-trust-guard`, please report it responsibly.
|
|
15
|
+
|
|
16
|
+
### How to Report
|
|
17
|
+
|
|
18
|
+
1. **DO NOT** create a public GitHub issue for security vulnerabilities
|
|
19
|
+
2. Email security concerns to: [security@example.com] (replace with actual contact)
|
|
20
|
+
3. Include the following information:
|
|
21
|
+
- Description of the vulnerability
|
|
22
|
+
- Steps to reproduce
|
|
23
|
+
- Potential impact
|
|
24
|
+
- Suggested fix (if any)
|
|
25
|
+
|
|
26
|
+
### What to Expect
|
|
27
|
+
|
|
28
|
+
- **Acknowledgment**: Within 48 hours
|
|
29
|
+
- **Initial Assessment**: Within 7 days
|
|
30
|
+
- **Resolution Timeline**: Depends on severity
|
|
31
|
+
- Critical: 24-72 hours
|
|
32
|
+
- High: 1-2 weeks
|
|
33
|
+
- Medium: 2-4 weeks
|
|
34
|
+
- Low: Next release cycle
|
|
35
|
+
|
|
36
|
+
### Severity Classification
|
|
37
|
+
|
|
38
|
+
| Severity | Description | Example |
|
|
39
|
+
|----------|-------------|---------|
|
|
40
|
+
| Critical | Complete bypass of security controls | Guard returns `allowed: true` for known attack |
|
|
41
|
+
| High | Significant reduction in protection | Pattern fails to detect major attack category |
|
|
42
|
+
| Medium | Limited bypass under specific conditions | Edge case pattern evasion |
|
|
43
|
+
| Low | Minor issues or improvements | Detection rate below optimal |
|
|
44
|
+
|
|
45
|
+
## Security Best Practices
|
|
46
|
+
|
|
47
|
+
### Using llm-trust-guard
|
|
48
|
+
|
|
49
|
+
1. **Defense in Depth**: Use multiple guards in combination
|
|
50
|
+
```typescript
|
|
51
|
+
// Recommended: Layer multiple guards
|
|
52
|
+
const sanitizer = new InputSanitizer();
|
|
53
|
+
const encoder = new EncodingDetector();
|
|
54
|
+
const memory = new MemoryGuard();
|
|
55
|
+
|
|
56
|
+
// Check all layers
|
|
57
|
+
const input1 = sanitizer.sanitize(userInput);
|
|
58
|
+
const input2 = encoder.detect(userInput);
|
|
59
|
+
const input3 = memory.validateContextInjection(context, sessionId);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
2. **Keep Updated**: Always use the latest version
|
|
63
|
+
```bash
|
|
64
|
+
npm update llm-trust-guard
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. **Configure Appropriately**: Adjust thresholds based on your risk tolerance
|
|
68
|
+
```typescript
|
|
69
|
+
// Stricter configuration for high-security environments
|
|
70
|
+
const sanitizer = new InputSanitizer({
|
|
71
|
+
threshold: 0.5, // Higher = stricter
|
|
72
|
+
papThreshold: 0.3, // Lower = more sensitive to PAP
|
|
73
|
+
blockCompoundPersuasion: true
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. **Monitor and Log**: Enable logging for security events
|
|
78
|
+
```typescript
|
|
79
|
+
const sanitizer = new InputSanitizer({
|
|
80
|
+
logMatches: true // Log detected patterns
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
5. **Validate All Sources**: Don't trust external data
|
|
85
|
+
```typescript
|
|
86
|
+
// Always validate RAG content
|
|
87
|
+
const ragGuard = new RAGGuard();
|
|
88
|
+
const result = ragGuard.validateDocument(externalDoc);
|
|
89
|
+
|
|
90
|
+
// Always validate memory/context
|
|
91
|
+
const memGuard = new MemoryGuard();
|
|
92
|
+
const ctxResult = memGuard.validateContextInjection(context, session);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Known Attack Vectors Protected
|
|
96
|
+
|
|
97
|
+
| Attack Vector | Guard(s) | OWASP Reference |
|
|
98
|
+
|---------------|----------|-----------------|
|
|
99
|
+
| Prompt Injection | InputSanitizer, EncodingDetector | LLM01:2025 |
|
|
100
|
+
| Jailbreaks | InputSanitizer (PAP detection) | LLM01:2025 |
|
|
101
|
+
| Sensitive Data Exposure | OutputFilter, PromptLeakageGuard | LLM02:2025 |
|
|
102
|
+
| Supply Chain Attacks | MCPSecurityGuard | LLM03:2025 |
|
|
103
|
+
| Data Poisoning | RAGGuard, MemoryGuard | LLM04:2025 |
|
|
104
|
+
| Privilege Escalation | PolicyGate, TenantBoundary | LLM05:2025 |
|
|
105
|
+
| System Prompt Leakage | PromptLeakageGuard | LLM07:2025 |
|
|
106
|
+
| Vector DB Attacks | RAGGuard | LLM08:2025 |
|
|
107
|
+
| Tool Misuse | ToolChainValidator | ASI04 |
|
|
108
|
+
| Privilege Escalation | PolicyGate | ASI05 |
|
|
109
|
+
| Memory Poisoning | MemoryGuard | ASI06 |
|
|
110
|
+
| State Corruption | ToolChainValidator | ASI07 |
|
|
111
|
+
| Trust Exploitation | TrustExploitationGuard | ASI09 |
|
|
112
|
+
|
|
113
|
+
### Security Limitations
|
|
114
|
+
|
|
115
|
+
1. **Not a Complete Solution**: This library is one layer of defense. Always implement:
|
|
116
|
+
- Input validation at application level
|
|
117
|
+
- Output sanitization
|
|
118
|
+
- Rate limiting
|
|
119
|
+
- Authentication/Authorization
|
|
120
|
+
- Logging and monitoring
|
|
121
|
+
|
|
122
|
+
2. **Pattern-Based Detection**: Relies on known patterns; novel attacks may evade detection initially
|
|
123
|
+
|
|
124
|
+
3. **Performance Trade-offs**: More thorough checks = higher latency
|
|
125
|
+
|
|
126
|
+
4. **False Positives**: Aggressive settings may block legitimate content
|
|
127
|
+
|
|
128
|
+
## Disclosure Policy
|
|
129
|
+
|
|
130
|
+
- We follow responsible disclosure practices
|
|
131
|
+
- Security fixes are released as soon as possible
|
|
132
|
+
- CVEs are requested for critical vulnerabilities
|
|
133
|
+
- Security advisories are published on GitHub
|
|
134
|
+
|
|
135
|
+
## Security Updates
|
|
136
|
+
|
|
137
|
+
Subscribe to security updates:
|
|
138
|
+
1. Watch this repository for releases
|
|
139
|
+
2. Check the CHANGELOG.md for security-related changes
|
|
140
|
+
3. Monitor npm advisories: `npm audit`
|
|
141
|
+
|
|
142
|
+
## Acknowledgments
|
|
143
|
+
|
|
144
|
+
We thank all security researchers who responsibly disclose vulnerabilities. Contributors will be acknowledged (with permission) in release notes.
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-trust-guard",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Comprehensive security guards for LLM-powered and agentic AI applications - 18+ protection layers covering OWASP Top 10 for LLMs 2025, Agentic Applications 2026, and MCP Security. Features prompt injection (PAP/persuasion), multi-modal attacks, RAG poisoning with embedding attack detection, memory persistence attacks, code execution sandboxing, multi-agent security, MCP tool shadowing prevention, system prompt leakage protection, human-agent trust exploitation (ASI09), tool chain validation v2 (ASI07/ASI04), and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
9
|
"README.md",
|
|
10
|
-
"LICENSE"
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"CONTRIBUTING.md",
|
|
12
|
+
"SECURITY.md",
|
|
13
|
+
"CHANGELOG.md"
|
|
11
14
|
],
|
|
15
|
+
"homepage": "https://www.npmjs.com/package/llm-trust-guard",
|
|
12
16
|
"scripts": {
|
|
13
17
|
"build": "tsc",
|
|
14
18
|
"prepublishOnly": "npm run build",
|