Thank you for considering contributing to InferShield! 🛡️
This document provides guidelines for contributing to the project. We welcome all forms of contribution: bug reports, feature requests, documentation improvements, and code contributions.
- Code of Conduct
- Getting Started
- How to Contribute
- Development Setup
- Pull Request Process
- Coding Standards
- Testing Guidelines
- Documentation
- Community
We are committed to providing a welcoming and inclusive environment. Please:
- Be respectful in all interactions
- Be constructive when giving feedback
- Be collaborative and help others
- Be patient with newcomers
Harassment, discrimination, or abusive behavior will not be tolerated.
- Report bugs - Found something broken? Let us know!
- Suggest features - Have an idea? Share it!
- Improve documentation - Typos, clarifications, examples
- Write code - Bug fixes, features, tests
- Add detection policies - New threat detection patterns
- Test & validate - Try InferShield in different environments
- Check existing issues to avoid duplicates
- Search discussions to see if your idea has been discussed
- Read the docs to understand the architecture
- Join discussions to get feedback before big changes
Use the bug report template when creating an issue. Include:
- Description: What happened vs. what should happen
- Reproduction: Step-by-step instructions to reproduce
- Environment: OS, Node version, InferShield version
- Logs: Relevant error messages or stack traces
- Screenshots: If applicable
For security vulnerabilities, please follow our Security Policy and report privately to security@infershield.io.
Use the feature request template. Include:
- Problem: What problem does this solve?
- Solution: Your proposed solution
- Alternatives: Other approaches you considered
- Use case: Real-world scenario where this helps
Start a discussion for large features before implementing.
Documentation improvements are always welcome:
- Fix typos or unclear explanations
- Add examples or use cases
- Write tutorials or guides
- Improve code comments
- Update outdated information
Small fixes (typos, broken links): Submit a PR directly.
Large changes (new guides, restructuring): Open an issue first to discuss.
- Node.js: v18+ (v20 recommended)
- PostgreSQL: 14+ (for backend)
- Git: For version control
- Docker (optional): For containerized development
# Fork the repo on GitHub, then clone your fork:
git clone https://github.com/YOUR-USERNAME/infershield.git
cd infershield
# Add upstream remote:
git remote add upstream https://github.com/InferShield/infershield.git# Backend
cd backend
npm install
cp .env.example .env # Configure your environment
# Proxy
cd ../proxy
npm install
cp .env.example .env
# Dashboard
cd ../dashboard
npm install
cp .env.example .env
# Extension (optional)
cd ../extension
npm installcd backend
# Start PostgreSQL (via Docker):
docker run -d \
--name infershield-postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=infershield \
-p 5432:5432 \
postgres:14
# Run migrations:
npx prisma migrate dev
# Seed demo data (optional):
npm run seed# Terminal 1 - Backend:
cd backend
npm run dev
# Terminal 2 - Proxy:
cd proxy
npm start
# Terminal 3 - Dashboard:
cd dashboard
npm startVisit:
- Backend: http://localhost:5000
- Proxy: http://localhost:8000
- Dashboard: http://localhost:3000
# Backend tests:
cd backend
npm test
# Proxy tests:
cd proxy
npm test
# Extension tests:
cd extension
npm test
# Run all tests (from root):
npm run test:all# Update your fork:
git checkout main
git pull upstream main
# Create a feature branch:
git checkout -b feature/your-feature-name
# or
git checkout -b fix/your-bug-fixBranch naming:
feature/- New featuresfix/- Bug fixesdocs/- Documentation onlyrefactor/- Code refactoringtest/- Test additions/fixes
- Write clean, readable code
- Follow existing code style
- Add tests for new functionality
- Update documentation as needed
- Keep commits atomic and focused
git add .
git commit -m "feat: add PII detection for passport numbers"Commit message format:
<type>: <description>
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style (formatting, no logic change)refactor: Code refactoringtest: Adding or updating testschore: Maintenance (dependencies, build config)
Examples:
feat: add support for Anthropic Claude models
fix: correct SSN validation regex for false positives
docs: update quickstart guide for Windows
test: add integration tests for API key generation
git push origin feature/your-feature-nameThen create a pull request on GitHub:
- Go to your fork on GitHub
- Click "Compare & pull request"
- Fill out the PR template
- Link related issues (e.g., "Closes #123")
- Request review
- Respond to feedback promptly
- Make requested changes
- Push additional commits (don't force-push during review)
- Mark conversations as resolved when addressed
Once approved, a maintainer will merge your PR. We use:
- Squash and merge for most PRs
- Merge commit for complex multi-commit PRs
- Rebase and merge rarely (only if history is clean)
- Style: Follow existing code style (we use Prettier)
- Linting: Run
npm run lintbefore committing - ES6+: Use modern JavaScript features
- Async/await: Prefer over callbacks and raw promises
- Error handling: Always catch errors and handle gracefully
- Modularity: Small, focused functions
- DRY: Don't repeat yourself
- Comments: Explain why, not what
- Naming: Descriptive names (not
x,tmp,data)
- Input validation: Validate all user input
- SQL injection: Use parameterized queries (Prisma handles this)
- XSS: Sanitize output in dashboard
- Secrets: Never commit API keys or passwords
- Unit tests: For business logic and utilities
- Integration tests: For API endpoints and database
- E2E tests: For critical user flows
Aim for:
- 80%+ coverage for new features
- 100% coverage for security-critical code
// Example unit test:
describe('PII Detection', () => {
it('should detect SSN in various formats', () => {
expect(detectSSN('123-45-6789')).toBe(true);
expect(detectSSN('123456789')).toBe(true);
expect(detectSSN('abc-de-fghi')).toBe(false);
});
});# Run all tests:
npm test
# Run specific test file:
npm test path/to/test.spec.js
# Run with coverage:
npm run test:coverage
# Watch mode (during development):
npm run test:watch- Functions: JSDoc comments for public APIs
- Complex logic: Inline comments explaining approach
- Types: Use TypeScript or JSDoc type annotations
/**
* Detects PII in the given text.
* @param {string} text - The text to analyze
* @param {Object} options - Detection options
* @param {boolean} options.strict - Use strict detection mode
* @returns {Array<PIIMatch>} Array of detected PII instances
*/
function detectPII(text, options = {}) {
// ...
}- README: Keep it concise and up-to-date
- Guides: Step-by-step tutorials in
/docs - API docs: OpenAPI/Swagger for REST endpoints
- Examples: Show real-world usage
- Update CHANGELOG.md for all user-facing changes
- Follow Keep a Changelog format
- Include version number and release date
Detection policies are the core of InferShield's threat detection capabilities. If you want to add a new detection pattern, this section will guide you through the process.
Detection policies are located in the backend/src/policies directory. Each policy is implemented as a separate module that exports a detection function.
All policies follow a consistent structure:
// backend/src/policies/examplePolicy.js
/**
* Example Policy: Detects [specific threat pattern]
* @param {Object} request - The request object to analyze
* @param {string} request.prompt - The user's prompt text
* @param {string} request.response - The LLM's response text (if available)
* @param {Object} request.metadata - Additional context (user ID, model, etc.)
* @param {Array} request.sessionHistory - Previous requests in this session
* @returns {Object} Detection result
*/
export async function detectExampleThreat(request) {
const findings = [];
// Your detection logic here
if (containsThreatPattern(request.prompt)) {
findings.push({
type: 'EXAMPLE_THREAT',
severity: 'HIGH', // LOW, MEDIUM, HIGH, CRITICAL
confidence: 0.85, // 0.0 - 1.0
description: 'Description of what was detected',
matchedPattern: 'specific pattern that triggered detection',
recommendation: 'How to mitigate this threat'
});
}
return {
detected: findings.length > 0,
findings,
riskScore: calculateRiskScore(findings) // 0-100
};
}
function containsThreatPattern(text) {
// Detection implementation
return /malicious-pattern/.test(text);
}
function calculateRiskScore(findings) {
// Risk scoring logic
return findings.length > 0 ? 75 : 0;
}-
Create a new file in
backend/src/policies/:touch backend/src/policies/yourPolicyName.js
-
Implement your detection logic following the structure above.
-
Register your policy in
backend/src/policies/index.js:import { detectExampleThreat } from './examplePolicy.js'; import { detectYourThreat } from './yourPolicyName.js'; // Add this export const policies = [ { name: 'example-threat', detect: detectExampleThreat }, { name: 'your-threat', detect: detectYourThreat }, // Add this ];
-
Add configuration in
backend/src/config/policies.js:export const policyConfig = { 'your-threat': { enabled: true, threshold: 0.7, // Confidence threshold for alerting severity: 'HIGH' } };
All new policies must include tests:
// backend/src/policies/__tests__/yourPolicyName.test.js
import { detectYourThreat } from '../yourPolicyName.js';
describe('Your Threat Detection', () => {
it('should detect malicious pattern', async () => {
const request = {
prompt: 'malicious input here',
metadata: {}
};
const result = await detectYourThreat(request);
expect(result.detected).toBe(true);
expect(result.findings).toHaveLength(1);
expect(result.findings[0].type).toBe('YOUR_THREAT');
});
it('should not flag benign input', async () => {
const request = {
prompt: 'normal user query',
metadata: {}
};
const result = await detectYourThreat(request);
expect(result.detected).toBe(false);
});
// Add more test cases for edge cases, false positives, etc.
});Run tests:
cd backend
npm test -- yourPolicyName.test.jsYour pull request should include:
- The policy file:
backend/src/policies/yourPolicyName.js - Registration: Update to
backend/src/policies/index.js - Configuration: Update to
backend/src/config/policies.js - Tests:
backend/src/policies/__tests__/yourPolicyName.test.js - Documentation: Add entry to
docs/DETECTION_POLICIES.md - Changelog: Update
CHANGELOG.mdunder "Unreleased"
Example PR title and description:
Title: feat: add detection for [specific threat type]
Description:
Adds a new detection policy for [threat type] attacks.
Detection approach:
- [Explain the detection logic]
- [Mention any patterns or heuristics used]
Test coverage:
- ✅ Detects malicious patterns
- ✅ Avoids false positives on benign input
- ✅ Handles edge cases (empty input, encoding, etc.)
Example detections:
- [Show 2-3 examples of what this policy catches]
Limitations:
- [Be honest about what this doesn't catch]
Good detection policies:
- ✅ Have clear, measurable detection criteria
- ✅ Minimize false positives
- ✅ Include confidence scores (not just binary detection)
- ✅ Provide actionable recommendations
- ✅ Document known limitations
Avoid:
- ❌ Overly broad patterns that flag benign content
- ❌ Hard-coded keywords without context analysis
- ❌ Expensive operations (heavy regex, external API calls)
- ❌ Non-deterministic behavior (unless intentional)
Before investing significant time:
- Open a discussion describing the threat pattern
- Share examples of attacks this would catch
- Get feedback on approach and false positive risk
This helps ensure your contribution aligns with project goals and avoids duplicate work.
- GitHub Issues: Bug reports, feature requests
- GitHub Discussions: Questions, ideas, general discussion
- Discord: Coming soon
- Email: security@infershield.io (security only)
- Documentation: Check
/docsfirst - Search issues: Your question may already be answered
- Ask in discussions: The community is here to help
- Be specific: Provide context, code samples, error messages
Contributors are recognized in:
- Release notes (for significant contributions)
- CONTRIBUTORS.md (all contributors)
- GitHub contributor graph
By contributing to InferShield, you agree that your contributions will be licensed under the MIT License.
Not sure where to start? Have questions about the contribution process?
- Open a discussion: GitHub Discussions
- Join the community: (Discord coming soon)
- Email: hello@infershield.io
Thank you for contributing to InferShield! Together, we're making LLM security accessible to everyone. 🛡️