Skip to Content
Alprina is in active development. Join us in building the future of security scanning.
CLI Referencealprina fix

alprina fix

Generate AI-powered fixes for security vulnerabilities discovered in your code.

Synopsis

alprina fix <target> [OPTIONS]

Description

The alprina fix command uses AI to automatically generate code fixes for security vulnerabilities found during scans. It can operate in interactive mode (asking for confirmation) or automatically apply fixes without user intervention.

This command is perfect for:

  • Quickly remediating security issues
  • Learning secure coding practices
  • Automating security fixes in CI/CD pipelines
  • Previewing potential fixes before applying them

Arguments

  • <target> - Path to file or directory to fix (required)

Options

--id

Specify a particular finding ID to fix instead of fixing all findings.

alprina fix ./app.py --id VULN-2024-001

--auto-fix

Automatically apply all fixes without asking for confirmation. Use with caution in production code.

alprina fix ./src --auto-fix

Warning: Always review auto-applied fixes and test your code after using this option.

--severity

Fix only vulnerabilities of a specific severity level.

Valid values: critical, high, medium, low

# Fix only critical issues alprina fix ./src --severity critical # Fix high and critical issues alprina fix ./src --severity high

--preview

Preview the fixes that would be applied without actually modifying any files.

alprina fix ./src --preview

This shows you a diff of proposed changes before you commit to applying them.

Examples

Fix a single file with confirmation prompts:

alprina fix ./app.py

Output:

πŸ› οΈ Alprina Fix Tool ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Found 3 vulnerabilities to fix: 1. HIGH: SQL Injection in database.py:42 2. MEDIUM: Hardcoded secret in config.py:15 3. LOW: Weak cryptography in auth.py:89 Fix vulnerability #1? [y/N]: y βœ“ Applied fix for SQL Injection

Auto-fix All Issues

Automatically fix all vulnerabilities in a directory:

alprina fix ./src --auto-fix

Use case: CI/CD pipelines where you trust the AI fixes.

Fix Only Critical Issues

Fix only critical vulnerabilities:

alprina fix ./src --severity critical

Preview Fixes

See what would be fixed without applying changes:

alprina fix ./src --preview

Output shows diffs:

File: database.py ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - query = f"SELECT * FROM users WHERE id = {user_id}" + query = "SELECT * FROM users WHERE id = ?" + cursor.execute(query, (user_id,)) βœ“ Would fix SQL injection vulnerability

Fix Specific Finding

Fix only a particular vulnerability:

alprina fix ./app.py --id VULN-2024-042

Workflow

  1. Scan First: Run alprina scan to find vulnerabilities
  2. Review Results: Check the scan report to understand issues
  3. Fix Issues: Run alprina fix to remediate
  4. Test Code: Always test your code after applying fixes
  5. Rescan: Run alprina scan again to verify fixes worked

Best Practices

Do:

βœ… Review AI-generated fixes before committing
βœ… Test your code after applying fixes
βœ… Use --preview first to see what will change
βœ… Fix critical issues first with --severity critical
βœ… Keep backups or use version control

Don’t:

❌ Blindly apply --auto-fix in production without testing
❌ Skip code review after AI fixes
❌ Assume all fixes are perfect (AI can make mistakes)
❌ Forget to run tests after applying fixes

Exit Codes

CodeMeaning
0All fixes applied successfully
1Error occurred during fixing
2No vulnerabilities found to fix
3User cancelled operation

Integration with Scan

The fix command works seamlessly with scan results:

# Scan and save results alprina scan ./src --output results.json # Fix issues from that scan alprina fix ./src # Verify fixes worked alprina scan ./src

CI/CD Integration

Example GitHub Actions workflow:

- name: Scan for vulnerabilities run: alprina scan ./src - name: Auto-fix critical issues run: alprina fix ./src --severity critical --auto-fix - name: Commit fixes run: | git config user.name "Alprina Bot" git add . git commit -m "fix: auto-remediate critical vulnerabilities" git push

Limitations

  • Only fixes issues that Alprina’s AI can confidently remediate
  • Some complex vulnerabilities may require manual intervention
  • Always review and test AI-generated fixes
  • Does not guarantee 100% security (defense in depth still required)

Troubleshooting

”No vulnerabilities found”

Run alprina scan first to detect issues before fixing.

”Cannot apply fix automatically”

Some vulnerabilities require manual intervention. Use alprina mitigate for guidance.

”Fix failed to apply”

The AI-generated fix may conflict with your code structure. Apply manually using the suggested fix from alprina mitigate.

Learn More

Last updated on