Skip to content

Comments

fix(server): harden auth, MCP, redirect, and snapshot endpoints#1312

Open
eren-karakus0 wants to merge 2 commits intoeigent-ai:mainfrom
eren-karakus0:fix/server-security-hardening
Open

fix(server): harden auth, MCP, redirect, and snapshot endpoints#1312
eren-karakus0 wants to merge 2 commits intoeigent-ai:mainfrom
eren-karakus0:fix/server-security-hardening

Conversation

@eren-karakus0
Copy link
Contributor

@eren-karakus0 eren-karakus0 commented Feb 19, 2026

Related Issue

Closes #1329

Split from #1299 as requested by @bytecii.

Summary

Security hardening for the server codebase.

Changes

  • auth.py: Add token expiry validation
  • history_controller.py: Add missing auth dependency to endpoint
  • mcp_controller.py: Harden input validation
  • user_controller.py: Harden input validation
  • redirect_controller.py: Sanitize redirect URLs with urllib.parse.quote to prevent open redirect
  • login_controller.py: Add login rate-limit headers
  • chat_snpshot.py: Add field validation to snapshot model

Tests (split into per-file modules matching source structure)

  • server/tests/app/controller/test_redirect_controller.py - URL encoding, XSS prevention
  • server/tests/app/controller/mcp/test_mcp_controller.py - install .get() safety
  • server/tests/app/controller/mcp/test_user_controller.py - IDOR get/delete
  • server/tests/app/controller/user/test_login_controller.py - blocked status handling
  • server/tests/app/component/test_auth.py - None token, user exists validation
  • server/tests/app/controller/chat/test_history_controller.py - total_failed_tasks
  • server/tests/app/model/chat/test_chat_snpshot.py - path traversal, valid ID

Files (14)

  • server/app/component/auth.py
  • server/app/controller/chat/history_controller.py
  • server/app/controller/mcp/mcp_controller.py
  • server/app/controller/mcp/user_controller.py
  • server/app/controller/redirect_controller.py
  • server/app/controller/user/login_controller.py
  • server/app/model/chat/chat_snpshot.py
  • server/tests/app/component/test_auth.py
  • server/tests/app/controller/chat/test_history_controller.py
  • server/tests/app/controller/mcp/test_mcp_controller.py
  • server/tests/app/controller/mcp/test_user_controller.py
  • server/tests/app/controller/test_redirect_controller.py
  • server/tests/app/controller/user/test_login_controller.py
  • server/tests/app/model/chat/test_chat_snpshot.py

- Add token expiry validation in auth component
- Add auth dependency to history_controller endpoint
- Sanitize redirect URLs to prevent open redirect
- Harden MCP controller and user_controller input validation
- Add login rate-limit headers to login_controller
- Add field validation to chat_snapshot model
- Add tests for all security fixes
@Wendong-Fan
Copy link
Contributor

thanks @eren-karakus0 , could you link the issue?

@eren-karakus0
Copy link
Contributor Author

Linked - closes #1329. Sorry for the delay!

Copy link
Collaborator

@bytecii bytecii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split them to correspond to changes of each file for example tests/app/controller/chat/history_controller.py etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - split into 7 separate test files matching the source structure:

  • tests/app/controller/redirect_controller.py
  • tests/app/controller/mcp/mcp_controller.py
  • tests/app/controller/mcp/user_controller.py
  • tests/app/controller/user/login_controller.py
  • tests/app/component/auth.py
  • tests/app/controller/chat/history_controller.py
  • tests/app/model/chat/chat_snpshot.py

All using def test_xxx style. Fixed in latest push.

cookies = request.cookies
cookies_json = json.dumps(cookies)

safe_code = html.escape(code, quote=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use following?

Suggested change
safe_code = html.escape(code, quote=True)
from urllib.parse import quote # move to top
safe_code = quote(code, safe='')

if code = "abc&def", html quote will convert to eigent://callback?code=abc&def
but quote will give code=abc%26def which should be the one we expect

Copy link
Contributor Author

@eren-karakus0 eren-karakus0 Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to urllib.parse.quote(code, safe='') which gives proper URL encoding (%26 instead of &). Fixed in latest push.

- Use urllib.parse.quote instead of html.escape for redirect callback
  code parameter (proper URL encoding vs HTML entity encoding)
- Split test_security_fixes.py into per-file test modules matching
  the source structure as requested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Server security: reflected XSS, MCP IDOR, login bypass, auth crash, snapshot path traversal

3 participants