Skip to content

[Bug] beacon_api.py: Stored XSS via /api/chat — user messages stored and returned unsanitized #3222

@haoyousun60-create

Description

@haoyousun60-create

Security Audit Finding

Severity: Medium
File: node/beacon_api.py:680-720 (chat endpoint)
Issue: The /api/chat endpoint stores user messages directly in the database and returns them without any HTML/script sanitization. An attacker can inject <script> tags or event handlers that execute when other users view the chat history.

Code:

@beacon_api.route('/api/chat', methods=['POST'])
def chat():
    data = request.get_json()
    message = data.get('message')  # No sanitization!
    db.execute(
        "INSERT INTO beacon_chat ... VALUES (?, 'user', ?, ...)",
        (agent_id, message, ...)  # Stored raw
    )

Impact:

  • Attacker can inject JavaScript that executes in other users' browsers
  • Session hijacking, credential theft, or phishing via injected content
  • The chat history endpoint returns raw stored content

Fix:

  1. Sanitize input: strip HTML tags or escape special characters
  2. Use Content-Security-Policy headers
  3. Return responses with Content-Type: application/json (already done, but ensure no HTML rendering)

Wallet: RTC4642c5ee8467f61ed91b5775b0eeba984dd776ba

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions