Skip to content

Add URL encoding for RabbitMQ credentials in AMQP URLs #2

@allipry

Description

@allipry

Problem

The AMQP URL construction in multiple files does not URL-encode the username and password:

rmq_url = f"amqp://{rmq_user}:{rmq_pass}@{rmq_host}:{rmq_port}/{rmq_vhost}"

If a password contains special characters like @, /, :, or #, the URL will be malformed and connection will fail.

Example

# Password with special characters
rmq_pass = "p@ss/word:123"

# Current (broken):
amqp://user:p@ss/word:123@localhost:5672/  # Parsing fails

# Fixed:
amqp://user:p%40ss%2Fword%3A123@localhost:5672/  # Works correctly

Solution

Use urllib.parse.quote() to encode credentials:

from urllib.parse import quote

rmq_url = f"amqp://{quote(rmq_user, safe='')}:{quote(rmq_pass, safe='')}@{rmq_host}:{rmq_port}/{rmq_vhost}"

Files Affected

  • opentakserver/app.py
  • opentakserver/cot_parser/cot_parser.py
  • opentakserver/eud_handler/client_controller.py

Related

Identified during code review of PR #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions