Skip to content

fix(connection): add port validation for connection port field#68777

Open
jlaportebot wants to merge 1 commit into
apache:mainfrom
jlaportebot:fix/connection-port-validation
Open

fix(connection): add port validation for connection port field#68777
jlaportebot wants to merge 1 commit into
apache:mainfrom
jlaportebot:fix/connection-port-validation

Conversation

@jlaportebot

Copy link
Copy Markdown

Summary

Add validation for the connection port field to ensure it's within the valid TCP/UDP range (0-65535) at every layer where connections are accepted or created.

Changes

  • Core Connection model (airflow.models.connection): Added _validate_port() static method and validation in __init__, _parse_from_uri, and from_json
  • Task SDK Connection (airflow.sdk.definitions.connection): Added __attrs_post_init__ validation
  • REST API (ConnectionBody in core_api/datamodels/connections.py): Added field validator for port
  • CLI (connection_command.py): Added explicit validation before creating Connection
  • Execution API (ConnectionTestConnectionResponse): Added field validator for port
  • ConnectionTestRequest SQLAlchemy model: Added _validate_port() and validation in __init__

Testing

Added comprehensive tests for all validation points:

  • Valid ports (0, 1, 80, 443, 3306, 5432, 8080, 65535) are accepted
  • None port is allowed (optional field)
  • Negative ports (-1) are rejected
  • Ports > 65535 are rejected (65536, 99999, 99999999)
  • Validation works for direct construction, URI parsing, and JSON deserialization

Closes #68382

Validate that the connection port field is within the valid TCP/UDP range (0-65535)
at every layer where connections are accepted or created:

- Core Connection model (airflow.models.connection)
- Task SDK Connection class (airflow.sdk.definitions.connection)
- REST API request model (ConnectionBody)
- CLI connection create/update command
- Execution API datamodel (ConnectionTestConnectionResponse)
- ConnectionTestRequest SQLAlchemy model

This prevents users from creating connections with invalid port numbers
(e.g., -1, 99999999) which would silently misbehave at runtime.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection port field does not validate that the value is a valid port number

1 participant