Skip to content

Conversation

@ashimov
Copy link
Contributor

@ashimov ashimov commented Jan 14, 2026

Summary

Security Fixes (Code Review Findings):

  • Critical: Added API key encryption using Fernet symmetric encryption
  • Critical: Added auth secret validation (32+ character minimum, no dev fallbacks)
  • Critical: Added rate limiting on sensitive endpoints (slowapi)
  • Critical: Added CSRF protection middleware
  • High: Added security headers (X-Frame-Options, X-Content-Type-Options, etc.)
  • High: Fixed session fixation vulnerability
  • High: Sanitized error messages to prevent information leakage
  • High: Fixed CORS headers (explicit whitelist instead of "*")
  • Medium: Replaced secrets.choice with uuid.uuid4() for session IDs
  • Medium: Fixed global mutable state in config snapshots
  • Medium: Added method whitelist for dynamic calls in firewall router
  • Medium: Replaced print statements with structured logging

New Files:

  • backend/utils/crypto.py - API key encryption utilities
  • backend/utils/logging.py - Structured logging with security events
  • backend/utils/audit.py - Audit logging for database events
  • backend/middleware/csrf.py - CSRF protection middleware

Dependencies Added:

  • cryptography>=41.0.0 - For Fernet encryption
  • slowapi>=0.1.9 - For rate limiting

Berik Ashimov and others added 13 commits December 25, 2025 22:45
  - Replaced all `Promise<any>` with proper `VyOSResponse` types in access-list API
  - Created shared `VyOSResponse` and `ApiError` interfaces in `lib/types/api.ts`
  - Removed unused `parseError` variable in API client
  - Improved type definitions for batch operations

- **Pydantic V2 Migration:**
  - Updated deprecated `Field(example=...)` to `json_schema_extra` in dummy.py and ethernet.py
  - Migrated `class Config` to `model_config = ConfigDict()` in interface routers
  - Added `ConfigDict` imports where needed

- **Backend Bug Fixes:**
  - Fixed async/await issue in `get_vyos_timezone()` function in power.py
  - Updated test client from deprecated httpx.AsyncClient to FastAPI TestClient

- **Security and Production Readiness:**
  - Updated .env.example files for HTTPS production deployment
  - Added HTTPS configuration examples for both frontend and backend

- **Code Quality:**
  - Removed unused variables and improved error handling
  - Updated deprecated Pydantic syntax for better compatibility

This commit addresses critical code review issues including type safety,
deprecated API usage, and production security configurations. All changes
maintain backward compatibility and do not break existing functionality.
, Community-VyProjects#113, Community-VyProjects#108

Security fixes:
- Add API key encryption using Fernet symmetric encryption
- Remove dev fallback for auth secret, require 32+ character secret
- Add rate limiting to authentication endpoints (slowapi)
- Add CSRF protection middleware with Origin/Referer validation
- Add security headers middleware (X-Frame-Options, CSP, HSTS, etc.)
- Fix session fixation vulnerability with token mismatch detection
- Replace detailed error messages with generic responses
- Fix CORS headers - replace wildcard with explicit whitelist
- Add method whitelist for dynamic firewall operations
- Replace secrets.choice with uuid.uuid4 for ID generation

Bug fixes:
- Community-VyProjects#131: Fix frontend restart loop - add build check before npm start
- Community-VyProjects#113: Improve DHCP leases parsing with regex for robust VyOS format handling
- Community-VyProjects#108: Fix SSL verification - clear service cache when instance settings change

Code quality:
- Add structured logging (replace print statements)
- Add audit logging utility for tracking user actions
- Fix global mutable state in config snapshots (use app.state)
- Improve CSV import validation (length limits, format checks, encryption)

New files:
- backend/utils/crypto.py - API key encryption utilities
- backend/utils/logging.py - structured logging utilities
- backend/utils/audit.py - audit logging for database
- backend/middleware/csrf.py - CSRF protection middleware

New dependencies:
- cryptography>=41.0.0
- slowapi>=0.1.9
@Jarnster Jarnster added bug Something isn't working enhancement New feature or request patch needed Issue that needs a patch (PR or commit) to resolve or improve security Involves security-related things (only public info) beta Report issues about experimental or beta releases labels Jan 14, 2026
@ashimov
Copy link
Contributor Author

ashimov commented Jan 16, 2026

Hi guys!Did you checked fixes?

@Jarnster
Copy link
Member

Hi guys!Did you checked fixes?

Hello! First of all, thank you very much for your work!

This is a large PR which involves a hefty amount of changes. This means that reviewing this takes a bit more time than usual. We need to make sure this PR doesn't break anything else. Multiple maintainers will need to review and agree before merging.

We've tried deploying your PR already, but encountered several issues regarding session handling. Can you reverify how this could have broke?

- Support both secure and non-secure cookie names (__Secure- prefix)
- Remove strict token validation causing random disconnections
- Fix API key fingerprint race condition in VyOS service cache
- Update frontend proxy for secure cookie support

Resolves production session issues reported by maintainers
@ashimov
Copy link
Contributor Author

ashimov commented Jan 17, 2026

Hi guys,

I've identified and fixed issues. The root cause was that the code wasn't handling Better-Auth's production-specific behavior:

What broke

  • Code only checked for better-auth.session_token cookie, but Better-Auth uses '__Secure-better-auth.session_token' in production -> 401 errors
  • Middleware was invalidating sessions when tokens regenerated (Better-Auth's rolling sessions security feature) → random disconnections
  • API key encryption state changes caused unnecessary VyOS service cache invalidations → timeouts
  • Frontend proxy hardcoded cookie name instead of reading it dynamically → auth failures

Fixed in 4 files

  • backend/middleware/session.py - Added secure cookie support + removed strict token validation
  • backend/routers/session/session.py - Secure cookie support in 3 endpoints
  • backend/session_vyos_service.py - Removed api_key from config fingerprint
  • frontend/src/app/api/session/[...path]/route.ts - Dynamic cookie name extraction

Now it's working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta Report issues about experimental or beta releases bug Something isn't working enhancement New feature or request patch needed Issue that needs a patch (PR or commit) to resolve or improve security Involves security-related things (only public info)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants