Thank you for your interest in contributing to NetTrailers! This document provides guidelines for contributing to the project.
- Fork the repository and clone it locally
- Install dependencies:
npm install - Set up environment variables: Copy
.env.local.exampleto.env.localand fill in required values - Run the development server:
npm run dev - Run tests:
npm test
feature/description- New featuresfix/description- Bug fixessecurity/description- Security-related changesdocs/description- Documentation updatesrefactor/description- Code refactoring
Use conventional commit format:
type(scope): description
[optional body]
[optional footer]
Types: feat, fix, docs, style, refactor, test, chore, security
- Create a feature branch from
main - Make your changes with clear, atomic commits
- Ensure all tests pass:
npm test - Run linting:
npm run lint - Run type checking:
npm run type-check - Open a PR with a clear description of changes
All mutation endpoints (POST, PUT, DELETE, PATCH) must live under /api/* to receive automatic CSRF protection from proxy.ts.
DO NOT:
- Create page-level POST handlers (e.g., in
app/page.tsx) - Perform state changes in GET handlers
- Skip CSRF validation for any state-changing operation
Correct pattern:
// app/api/my-endpoint/route.ts
export async function POST(request: NextRequest) {
// CSRF protection automatically applied by proxy.ts
// ... your handler logic
}Files using the 'use server' directive must implement CSRF protection:
- Import
validateServerActionOriginfrom@/lib/csrfProtection - Call it at the start of every exported function
- Throw an error if validation fails
Required pattern:
'use server'
import { headers } from 'next/headers'
import { validateServerActionOrigin } from '@/lib/csrfProtection'
export async function myServerAction(data: FormData) {
// CSRF protection - required for all server actions
const headersList = await headers()
if (!validateServerActionOrigin(headersList)) {
throw new Error('CSRF validation failed')
}
// ... action logic
}Automated enforcement: The test at __tests__/security/serverActionCsrf.test.ts will fail if server actions are missing CSRF protection.
For authenticated endpoints, use the withAuth middleware:
import { withAuth } from '@/lib/auth-middleware'
async function handler(request: NextRequest, userId: string) {
// userId is verified via Firebase Admin SDK
}
export const POST = withAuth(handler)- Always validate and sanitize user input
- Use parameterized queries for database operations
- Escape output to prevent XSS
- For AI-related endpoints, use
isomorphic-dompurifyfor sanitization
- Never commit secrets to the repository
- Use environment variables for all sensitive values
- Document required environment variables in
.env.local.example - Never log sensitive values
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # With coverage report
npm test -- --testPathPatterns=security # Security tests onlySecurity-related tests are located in:
__tests__/lib/csrfProtection.test.ts- CSRF protection unit tests__tests__/proxy.test.ts- Proxy/middleware integration tests__tests__/security/- Security enforcement tests
Always run security tests before submitting security-related PRs.
- Test both success and error paths
- Include edge cases for security-sensitive code
- Mock external services (Firebase, TMDB, etc.)
- Use
@jest-environment nodefor API route tests
- TypeScript is required for all new code
- Follow existing patterns in the codebase
- Use functional components with hooks
- Prefer Zustand stores over prop drilling
- Keep components focused and composable
- Update
README.mdfor user-facing changes - Update
CLAUDE.mdfor architecture changes - Add JSDoc comments for public functions
- Document security implications in code comments
If you have questions about contributing, please open an issue for discussion.