Overview
When you connect a repository in Nectr, the system automatically:- Creates a webhook on the GitHub repository
- Generates a unique secret for signature verification
- Configures the webhook to listen for PR events
- Stores the webhook secret in the database
Automatic Webhook Installation
Webhooks are automatically installed when you connect a repository through the Nectr UI.Installation Process
User Connects Repository
POST /api/v1/repos/{owner}/{repo}/installGenerate Webhook Secret
Install Webhook via GitHub API
pull_request- PR opened, updated, closed, etc.issues- Issue opened, updated, closed, etc.
Store Webhook in Database
app/integrations/github/webhook_manager.py:10-48
Webhook Configuration
Webhook Properties
Per-Repo vs Global Secrets
Nectr uses per-repository webhook secrets for security:- ✅ Each repository has a unique webhook secret
- ✅ Secrets are generated automatically on connection
- ✅ Stored in the database
installationstable - ✅ Falls back to
GITHUB_WEBHOOK_SECRETenv var if not found
Signature Verification
Nectr verifies that webhook requests actually came from GitHub using HMAC-SHA256 signature verification.How It Works
GitHub Signs Every Webhook
GitHub Signs Every Webhook
X-Hub-Signature-256 header.Nectr Verifies the Signature
Nectr Verifies the Signature
hmac.compare_digest()? Prevents timing attacks by comparing strings in constant time.Verification is Enforced in Production
Verification is Enforced in Production
- Development: Signature verification is skipped
- Production: Invalid signatures are rejected with 403
Event Processing
1. Webhook Receiver
The webhook endpoint receives events and returns200 OK immediately to avoid GitHub’s 10-second timeout.
- Returns
200 OKwithin milliseconds - Actual PR review happens in background task
- GitHub’s 10-second timeout is avoided
2. GitHub App Event Filtering
Nectr uses per-repo webhooks, not GitHub App webhooks. GitHub App events are rejected:3. Deduplication
Nectr prevents duplicate reviews by checking for recent pending/processing events:- Same PR number
- Same repository
- Within 1 hour
- Status: pending or processing
4. Background Processing
PR reviews happen in background tasks that can take 30-60 seconds:app/api/v1/webhooks.py:41-93
Event Types
Nectr processes specific pull request events:opened and synchronize events trigger AI reviews.
Webhook Management
Viewing Webhooks
Check installed webhooks for a repository:Disconnecting a Repository
When you disconnect a repository, Nectr automatically removes the webhook:Testing Webhooks
Local Development with ngrok
GitHub webhooks require a public URL. Use ngrok to expose your local server:Install ngrok
Start your local backend
Create ngrok tunnel
Update BACKEND_URL
BACKEND_URL to the ngrok URL:Connect a test repository
Manual Webhook Testing
Test the webhook endpoint directly:Troubleshooting
Webhook Not Triggering Reviews
Webhook Not Triggering Reviews
- Webhook not installed
- Check:
https://github.com/{owner}/{repo}/settings/hooks - Solution: Reconnect the repository in Nectr
- Check:
- Wrong webhook URL
- Check: Webhook payload URL should be
{BACKEND_URL}/api/v1/webhooks/github - Solution: Update
BACKEND_URLand reconnect repository
- Check: Webhook payload URL should be
- Event type not supported
- Only
pull_requestevents with actionsopenedorsynchronizetrigger reviews - Check GitHub webhook delivery logs for event details
- Only
- Signature verification failing
- Check logs for:
Invalid webhook signature for {repo} - Solution: Reconnect repository to regenerate secret
- Check logs for:
403 Invalid Webhook Signature
403 Invalid Webhook Signature
- Reconnect the repository to generate a new webhook secret
- Check that
APP_ENV=productionis set correctly - Verify the secret in database matches the webhook configuration in GitHub
- Check that you’re not modifying the request body before verification
GitHub Webhook Delivery Failed
GitHub Webhook Delivery Failed
- Check that
BACKEND_URLis publicly accessible - Verify SSL certificate is valid (required for production)
- Check firewall/network rules
- View delivery details in GitHub webhook settings: Recent Deliveries tab
Duplicate Reviews Posted
Duplicate Reviews Posted
- Check for duplicate webhook configurations in GitHub settings
- Verify only one active
Installationrecord exists for the repo - Check logs for “duplicate_skipped” messages
- Ensure database is accessible (deduplication queries database)
Events Stuck in 'Processing' Status
Events Stuck in 'Processing' Status
- Check backend logs for errors in
process_pr_in_background - Verify AI service (Anthropic) is accessible
- Check GitHub API rate limits
- Look for database connection issues
- Manually update event status in database if needed
Security Best Practices
Always Use Signature Verification in Production
Always Use Signature Verification in Production
Use HTTPS in Production
Use HTTPS in Production
Keep Webhook Secrets Secure
Keep Webhook Secrets Secure
- Secrets are stored in plaintext in the database (they’re not sensitive like OAuth tokens)
- Each repository has a unique secret
- Secrets are generated with
secrets.token_hex(32)(cryptographically secure) - Never log or expose webhook secrets in error messages
Monitor Webhook Deliveries
Monitor Webhook Deliveries
https://github.com/{owner}/{repo}/settings/hooks/{webhook_id}Look for:- Failed deliveries (red X)
- Response codes other than 200
- Timeout errors