kiba-core 0.5.3.dev96__tar.gz → 0.5.3.dev98__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/CHANGELOG.md +15 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/PKG-INFO +1 -1
- kiba_core-0.5.3.dev98/core/api/middleware/blocked_ip_middleware.py +69 -0
- kiba_core-0.5.3.dev98/core/api/middleware/gzip_middleware.py +21 -0
- kiba_core-0.5.3.dev98/core/api/middleware/public_cors_middleware.py +41 -0
- kiba_core-0.5.3.dev98/core/api/middleware/security_headers_middleware.py +26 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/request_body.py +1 -1
- kiba_core-0.5.3.dev98/core/auth_tokens/auth_token_invalidation_store.py +14 -0
- kiba_core-0.5.3.dev98/core/auth_tokens/dict_auth_token_invalidation_store.py +25 -0
- kiba_core-0.5.3.dev98/core/auth_tokens/sql_auth_token_invalidation_store.py +56 -0
- kiba_core-0.5.3.dev98/core/http/signed_token_manager.py +53 -0
- kiba_core-0.5.3.dev98/core/mcp/mcp_identity_provider.py +15 -0
- kiba_core-0.5.3.dev98/core/mcp/mcp_oauth_server.py +350 -0
- kiba_core-0.5.3.dev98/core/mcp/mcp_routes.py +213 -0
- kiba_core-0.5.3.dev98/core/mcp/mcp_server.py +235 -0
- kiba_core-0.5.3.dev98/core/mcp/model.py +63 -0
- kiba_core-0.5.3.dev98/core/util/number_util.py +17 -0
- kiba_core-0.5.3.dev98/core/web3/erc20.py +62 -0
- kiba_core-0.5.3.dev98/core/web3/erc4626.py +251 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/web3/eth_client.py +30 -16
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/web3/multicall3.py +1 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/kiba_core.egg-info/PKG-INFO +1 -1
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/kiba_core.egg-info/SOURCES.txt +30 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/pyproject.toml +1 -1
- kiba_core-0.5.3.dev98/tests/api/test_blocked_ip_middleware.py +89 -0
- kiba_core-0.5.3.dev98/tests/api/test_gzip_middleware.py +28 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_json_route.py +7 -0
- kiba_core-0.5.3.dev98/tests/api/test_public_cors_middleware.py +50 -0
- kiba_core-0.5.3.dev98/tests/auth_tokens/test_auth_token_invalidation_store.py +46 -0
- kiba_core-0.5.3.dev98/tests/cron/__init__.py +0 -0
- kiba_core-0.5.3.dev98/tests/http/__init__.py +0 -0
- kiba_core-0.5.3.dev98/tests/http/test_signed_token_manager.py +57 -0
- kiba_core-0.5.3.dev98/tests/mcp/__init__.py +0 -0
- kiba_core-0.5.3.dev98/tests/mcp/conftest.py +156 -0
- kiba_core-0.5.3.dev98/tests/mcp/test_mcp_oauth.py +279 -0
- kiba_core-0.5.3.dev98/tests/mcp/test_mcp_server.py +146 -0
- kiba_core-0.5.3.dev98/tests/requester/__init__.py +0 -0
- kiba_core-0.5.3.dev98/tests/util/test_number_util.py +26 -0
- kiba_core-0.5.3.dev98/tests/web3/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.github/pull_request_template.md +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.github/workflows/deploy.yml +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.github/workflows/publish.yml +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.github/workflows/pull-request.yml +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.github/workflows/release.yml +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/.gitignore +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/Dockerfile +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/README.md +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/api_request.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/api_response.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/authorizer.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/default_routes.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/health.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/json_route.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/database_connection_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/exception_handling_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/logging_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/origin_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/middleware/server_headers_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/openapi.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/rate_limit.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/request_context.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/route.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/route_auth.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/route_metadata.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/streaming_json_route.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/api/uploaded_file.py +0 -0
- {kiba_core-0.5.3.dev96/core/caching → kiba_core-0.5.3.dev98/core/auth_tokens}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/aws_requester.py +0 -0
- {kiba_core-0.5.3.dev96/core/cron → kiba_core-0.5.3.dev98/core/caching}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/caching/cache.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/caching/dict_cache.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/caching/file_cache.py +0 -0
- {kiba_core-0.5.3.dev96/core/locks → kiba_core-0.5.3.dev98/core/cron}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/cron/api_request_cron_job_processor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/cron/cron_executor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/cron/cron_job_processor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/cron/model.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/exceptions.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/http/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/http/basic_authentication.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/http/jwt.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/http/rest_method.py +0 -0
- {kiba_core-0.5.3.dev96/core/notifications → kiba_core-0.5.3.dev98/core/locks}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/locks/lock.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/locks/model.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/locks/sql.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/logging.py +0 -0
- {kiba_core-0.5.3.dev96/core/queues → kiba_core-0.5.3.dev98/core/mcp}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96/core/store → kiba_core-0.5.3.dev98/core/notifications}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/notifications/discord_client.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/notifications/notification_client.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/notifications/slack_client.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/py.typed +0 -0
- {kiba_core-0.5.3.dev96/core/util → kiba_core-0.5.3.dev98/core/queues}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/aqs.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/cosmos.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/message_queue.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/message_queue_processor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/model.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/sql.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/queues/sqs.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/requester/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/requester/requester.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/s3_manager.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/service_client.py +0 -0
- {kiba_core-0.5.3.dev96/core/web3 → kiba_core-0.5.3.dev98/core/store}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/store/database.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/store/entity_repository.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/store/retriever.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/store/saver.py +0 -0
- {kiba_core-0.5.3.dev96/tests/cron → kiba_core-0.5.3.dev98/core/util}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/async_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/chain_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/date_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/dict_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/file_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/hashing_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/http_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/json_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/list_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/process_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/string_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/typing_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/url_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/util/value_holder.py +0 -0
- {kiba_core-0.5.3.dev96/tests/requester → kiba_core-0.5.3.dev98/core/web3}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/core/web3/eth_client_registry.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/kiba_core.egg-info/dependency_links.txt +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/kiba_core.egg-info/requires.txt +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/kiba_core.egg-info/top_level.txt +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/makefile +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/setup.cfg +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_api_response.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_authorizer.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_database_connection_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_exception_handling_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_openapi.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_origin_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_rate_limit.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_request_context.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_route.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/api/test_streaming_json_route.py +0 -0
- {kiba_core-0.5.3.dev96/tests/web3 → kiba_core-0.5.3.dev98/tests/auth_tokens}/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/caching/test_dict_cache.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/caching/test_file_cache.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/cron/test_cron_executor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/locks/test_sql_lock.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/conftest.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/test_aqs_queue.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/test_cosmos_queue.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/test_message_queue_processor.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/test_sql_queue.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/queues/test_sqs_queue.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/requester/test_requester.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/test_database.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/test_entity_repository.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/test_exceptions.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/test_logging.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/__init__.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_async_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_chain_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_date_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_dict_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_file_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_json_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_list_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_process_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_string_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/util/test_url_util.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/web3/test_eth_client_registry.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/tests/web3/test_rest_eth_client.py +0 -0
- {kiba_core-0.5.3.dev96 → kiba_core-0.5.3.dev98}/uv.lock +0 -0
|
@@ -8,6 +8,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
+
- [MINOR] Added `core.api.middleware.blocked_ip_middleware.BlockedIpMiddleware` to answer 403 to requests from `blockedNetworks` (CIDRs) or a loaded `TorExitList`, checking every hop in `trustedProxyHeaders` and the socket peer
|
|
12
|
+
- [MINOR] Added `core.api.middleware.public_cors_middleware.PublicCorsMiddleware` to let any origin call the given `paths` (add it after starlette's `CORSMiddleware` so it answers their preflights first)
|
|
13
|
+
- [MINOR] Added `core.api.middleware.security_headers_middleware.SecurityHeadersMiddleware` to add fixed headers to every response
|
|
14
|
+
- [MINOR] Added `core.api.middleware.gzip_middleware.GZipMiddleware`, starlette's `GZipMiddleware` with `excludedPaths` and `excludedPathSuffixes` that are never compressed (e.g. responses carrying tokens, against BREACH)
|
|
15
|
+
- [MAJOR] Renamed `RestEthClient._make_request` to `make_request` for RPC methods without a helper (e.g. bundler methods)
|
|
16
|
+
- [MINOR] Added `RestEthClient.get_balance`, `get_storage_at` and `get_safe_block_number`
|
|
17
|
+
- [MINOR] Added `getEthBalance` to `MULTICALL3_ABI`
|
|
18
|
+
- [MINOR] Added `core.web3.erc20` (`ERC20_ABI`, `ERC20_TRANSFER_EVENT_TOPIC`) and `core.web3.erc4626` (`ERC4626_ABI`)
|
|
19
|
+
- [MINOR] Added `core.util.number_util.short_format_number`, matching `shortFormatNumber` in `@kibalabs/core`
|
|
20
|
+
- [MAJOR] Moved `core.mcp.oauth_store` to `core.auth_tokens`: `McpOAuthStore`, `DictMcpOAuthStore` and `SqlMcpOAuthStore` are now `AuthTokenInvalidationStore`, `DictAuthTokenInvalidationStore` and `SqlAuthTokenInvalidationStore`, with `claim`/`is_claimed` renamed to `invalidate`/`is_invalidated`. `McpOAuthClaimsTable` is now `AuthTokenInvalidationsTable` (`tbl_auth_token_invalidations`), which adds an `id` primary key and a `created_date` column and makes `key` unique, so apps that already created `tbl_mcp_oauth_claims` need a migration
|
|
21
|
+
- [MINOR] Added `core.http.signed_token_manager.SignedTokenManager` to create and validate typed HS256 JWTs (each with its own `tokenId`, so an `AuthTokenInvalidationStore` can make them single-use); `McpOAuthServer` uses it for its tokens
|
|
22
|
+
- [MINOR] Added `core.mcp.mcp_server.McpServer` to serve MCP tools over streamable HTTP for both the `2026-07-28` (per-request `_meta`) and `2025-03-26`–`2025-11-25` (`initialize`) protocol eras; tools take a pydantic arguments model and an optional output model
|
|
23
|
+
- [MINOR] Added `core.mcp.mcp_oauth_server.McpOAuthServer`, an OAuth 2.1 authorization server for MCP clients that delegates login to a `core.mcp.mcp_identity_provider.McpIdentityProvider` and shows a per-client consent page first; single-use and revoked tokens are recorded in a `core.mcp.oauth_store` store (`DictMcpOAuthStore`, or `SqlMcpOAuthStore` whose `McpOAuthClaimsTable` apps add to their migrations)
|
|
24
|
+
- [MINOR] Added `core.mcp.mcp_routes.create_mcp_routes` to mount both on a starlette app
|
|
25
|
+
- [MINOR] Updated `json_route` and `streaming_json_route` (via `read_request_body`) to accept `application/x-www-form-urlencoded` bodies
|
|
11
26
|
- [MINOR] Added `excludedPaths` (exact) and `excludedPathPrefixes` to `DatabaseConnectionMiddleware`: matching requests run without a context connection, e.g. a long-lived SSE stream that shouldn't hold a pooled connection and open transaction, or routes that use a different database
|
|
12
27
|
- [PATCH] Updated `ExceptionHandlingMiddleware` to answer a client that disconnects before the response starts (starlette's `ClientDisconnect`, e.g. while reading the body) with a 499 instead of logging a traceback and a 500
|
|
13
28
|
- [MAJOR] Added `priority` to `SqlMessageQueue.send_message` and `send_messages` (default 0): visible messages are claimed highest priority first, then by `visibleDate`, and a duplicate send, or a retry folded into a pending duplicate, keeps the higher priority. `tbl_queue_messages` has a new `priority` column (`INTEGER NOT NULL DEFAULT 0`), so apps must add it with a migration before upgrading
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import ipaddress
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
from starlette.datastructures import Headers
|
|
5
|
+
from starlette.responses import Response
|
|
6
|
+
from starlette.types import ASGIApp
|
|
7
|
+
from starlette.types import Receive
|
|
8
|
+
from starlette.types import Scope
|
|
9
|
+
from starlette.types import Send
|
|
10
|
+
|
|
11
|
+
from core import logging
|
|
12
|
+
from core.requester import Requester
|
|
13
|
+
|
|
14
|
+
IpAddress = ipaddress.IPv4Address | ipaddress.IPv6Address
|
|
15
|
+
|
|
16
|
+
TOR_EXIT_LIST_URL = 'https://check.torproject.org/torbulkexitlist'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _parse_ip(value: str) -> IpAddress | None:
|
|
20
|
+
try:
|
|
21
|
+
return ipaddress.ip_address(value.strip())
|
|
22
|
+
except ValueError:
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TorExitList:
|
|
27
|
+
def __init__(self, requester: Requester) -> None:
|
|
28
|
+
self.requester = requester
|
|
29
|
+
self.addresses: frozenset[IpAddress] = frozenset()
|
|
30
|
+
|
|
31
|
+
async def load(self) -> None:
|
|
32
|
+
try:
|
|
33
|
+
response = await self.requester.get(url=TOR_EXIT_LIST_URL, timeout=30)
|
|
34
|
+
except Exception as exception: # noqa: BLE001
|
|
35
|
+
logging.error(f'Failed to load Tor exit list, Tor exits will not be blocked: {exception}')
|
|
36
|
+
return
|
|
37
|
+
self.addresses = frozenset(address for address in (_parse_ip(value=line) for line in response.text.splitlines()) if address is not None)
|
|
38
|
+
logging.info(f'Loaded {len(self.addresses)} Tor exit addresses')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class BlockedIpMiddleware:
|
|
42
|
+
def __init__(self, app: ASGIApp, blockedNetworks: Collection[str] = (), torExitList: TorExitList | None = None, trustedProxyHeaders: Collection[str] = ()) -> None:
|
|
43
|
+
self.app = app
|
|
44
|
+
self.blockedNetworks = [ipaddress.ip_network(network) for network in blockedNetworks]
|
|
45
|
+
self.torExitList = torExitList
|
|
46
|
+
self.trustedProxyHeaders = tuple(trustedProxyHeaders)
|
|
47
|
+
|
|
48
|
+
def _is_blocked_ip(self, value: str) -> bool:
|
|
49
|
+
address = _parse_ip(value=value)
|
|
50
|
+
if address is None:
|
|
51
|
+
return False
|
|
52
|
+
if self.torExitList is not None and address in self.torExitList.addresses:
|
|
53
|
+
return True
|
|
54
|
+
return any(address in network for network in self.blockedNetworks)
|
|
55
|
+
|
|
56
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
57
|
+
if scope['type'] != 'http':
|
|
58
|
+
await self.app(scope, receive, send)
|
|
59
|
+
return
|
|
60
|
+
headers = Headers(scope=scope)
|
|
61
|
+
# NOTE(krishan711): every hop in the proxy headers is checked (not just the first like OriginIpMiddleware) so a spoofed first hop can't hide a blocked address
|
|
62
|
+
candidateIps = [value for headerName in self.trustedProxyHeaders for value in headers.get(headerName, '').split(',')]
|
|
63
|
+
client = scope.get('client')
|
|
64
|
+
if client:
|
|
65
|
+
candidateIps.append(str(client[0]))
|
|
66
|
+
if any(self._is_blocked_ip(value=candidateIp) for candidateIp in candidateIps):
|
|
67
|
+
await Response(status_code=403)(scope, receive, send)
|
|
68
|
+
return
|
|
69
|
+
await self.app(scope, receive, send)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from collections.abc import Collection
|
|
2
|
+
|
|
3
|
+
from starlette.middleware import gzip
|
|
4
|
+
from starlette.types import ASGIApp
|
|
5
|
+
from starlette.types import Receive
|
|
6
|
+
from starlette.types import Scope
|
|
7
|
+
from starlette.types import Send
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GZipMiddleware(gzip.GZipMiddleware):
|
|
11
|
+
# NOTE(krishan711): exclude responses that carry secrets (tokens, signed urls): compressing them enables BREACH
|
|
12
|
+
def __init__(self, app: ASGIApp, minimum_size: int = 500, compresslevel: int = 9, excludedPaths: Collection[str] = (), excludedPathSuffixes: Collection[str] = ()) -> None:
|
|
13
|
+
super().__init__(app=app, minimum_size=minimum_size, compresslevel=compresslevel)
|
|
14
|
+
self.excludedPaths = frozenset(excludedPaths)
|
|
15
|
+
self.excludedPathSuffixes = tuple(excludedPathSuffixes)
|
|
16
|
+
|
|
17
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
18
|
+
if scope['type'] == 'http' and (scope['path'] in self.excludedPaths or scope['path'].endswith(self.excludedPathSuffixes)):
|
|
19
|
+
await self.app(scope, receive, send)
|
|
20
|
+
return
|
|
21
|
+
await super().__call__(scope, receive, send)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from collections.abc import Collection
|
|
2
|
+
|
|
3
|
+
from starlette.datastructures import MutableHeaders
|
|
4
|
+
from starlette.responses import Response
|
|
5
|
+
from starlette.types import ASGIApp
|
|
6
|
+
from starlette.types import Message
|
|
7
|
+
from starlette.types import Receive
|
|
8
|
+
from starlette.types import Scope
|
|
9
|
+
from starlette.types import Send
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# NOTE(krishan711): add this after starlette's CORSMiddleware so it runs outside it, otherwise CORSMiddleware rejects
|
|
13
|
+
# preflights for these paths from origins it doesn't allow before they get here
|
|
14
|
+
class PublicCorsMiddleware:
|
|
15
|
+
def __init__(self, app: ASGIApp, paths: Collection[str], allowedMethods: Collection[str] = ('GET',)) -> None:
|
|
16
|
+
self.app = app
|
|
17
|
+
self.paths = frozenset(paths)
|
|
18
|
+
self.allowMethodsHeader = ', '.join([*allowedMethods, 'OPTIONS'])
|
|
19
|
+
|
|
20
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
21
|
+
if scope['type'] != 'http' or scope['path'] not in self.paths:
|
|
22
|
+
await self.app(scope, receive, send)
|
|
23
|
+
return
|
|
24
|
+
if scope['method'] == 'OPTIONS':
|
|
25
|
+
response = Response(
|
|
26
|
+
status_code=204,
|
|
27
|
+
headers={
|
|
28
|
+
'Access-Control-Allow-Origin': '*',
|
|
29
|
+
'Access-Control-Allow-Methods': self.allowMethodsHeader,
|
|
30
|
+
'Access-Control-Allow-Headers': '*',
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
await response(scope, receive, send)
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
async def send_with_cors_header(message: Message) -> None:
|
|
37
|
+
if message['type'] == 'http.response.start':
|
|
38
|
+
MutableHeaders(scope=message).setdefault('Access-Control-Allow-Origin', '*')
|
|
39
|
+
await send(message)
|
|
40
|
+
|
|
41
|
+
await self.app(scope, receive, send_with_cors_header)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
|
|
3
|
+
from starlette.datastructures import MutableHeaders
|
|
4
|
+
from starlette.types import ASGIApp
|
|
5
|
+
from starlette.types import Message
|
|
6
|
+
from starlette.types import Receive
|
|
7
|
+
from starlette.types import Scope
|
|
8
|
+
from starlette.types import Send
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SecurityHeadersMiddleware:
|
|
12
|
+
def __init__(self, app: ASGIApp, headers: Mapping[str, str]) -> None:
|
|
13
|
+
self.app = app
|
|
14
|
+
self.headers = dict(headers)
|
|
15
|
+
|
|
16
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
17
|
+
if scope['type'] != 'http':
|
|
18
|
+
await self.app(scope, receive, send)
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
async def send_with_security_headers(message: Message) -> None:
|
|
22
|
+
if message['type'] == 'http.response.start':
|
|
23
|
+
MutableHeaders(scope=message).update(self.headers)
|
|
24
|
+
await send(message)
|
|
25
|
+
|
|
26
|
+
await self.app(scope, receive, send_with_security_headers)
|
|
@@ -11,7 +11,7 @@ from core.util.typing_util import JsonObject
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
async def read_request_body(request: Request) -> Mapping[str, object]:
|
|
14
|
-
if request.headers.get('Content-Type', '').startswith('multipart/form-data'):
|
|
14
|
+
if request.headers.get('Content-Type', '').startswith(('multipart/form-data', 'application/x-www-form-urlencoded')):
|
|
15
15
|
body: dict[str, object] = {}
|
|
16
16
|
# NOTE(krishan711): the form is closed on exit so uploaded files' temporary files are closed (their content has been read by then)
|
|
17
17
|
async with request.form() as form:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from abc import ABC
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# NOTE(krishan711): records auth tokens (OAuth states, codes, refresh tokens, link secrets) and grants that must not be
|
|
7
|
+
# accepted again. Keep each invalidation until the token itself has expired; deleting one makes the token valid again
|
|
8
|
+
class AuthTokenInvalidationStore(ABC):
|
|
9
|
+
# NOTE(krishan711): must be atomic: only the first invalidation of an unexpired key returns True
|
|
10
|
+
@abstractmethod
|
|
11
|
+
async def invalidate(self, key: str, lifetime: datetime.timedelta) -> bool: ...
|
|
12
|
+
|
|
13
|
+
@abstractmethod
|
|
14
|
+
async def is_invalidated(self, key: str) -> bool: ...
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
from core.auth_tokens.auth_token_invalidation_store import AuthTokenInvalidationStore
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# NOTE(krishan711): only safe for a single process that is never restarted mid-flow; use SqlAuthTokenInvalidationStore otherwise
|
|
7
|
+
class DictAuthTokenInvalidationStore(AuthTokenInvalidationStore):
|
|
8
|
+
def __init__(self) -> None:
|
|
9
|
+
self._expiryDates: dict[str, datetime.datetime] = {}
|
|
10
|
+
|
|
11
|
+
async def invalidate(self, key: str, lifetime: datetime.timedelta) -> bool:
|
|
12
|
+
self._remove_expired()
|
|
13
|
+
if key in self._expiryDates:
|
|
14
|
+
return False
|
|
15
|
+
self._expiryDates[key] = datetime.datetime.now(tz=datetime.UTC) + lifetime
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
async def is_invalidated(self, key: str) -> bool:
|
|
19
|
+
self._remove_expired()
|
|
20
|
+
return key in self._expiryDates
|
|
21
|
+
|
|
22
|
+
def _remove_expired(self) -> None:
|
|
23
|
+
now = datetime.datetime.now(tz=datetime.UTC)
|
|
24
|
+
for key in [key for key, expiryDate in self._expiryDates.items() if expiryDate <= now]:
|
|
25
|
+
del self._expiryDates[key]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
import sqlalchemy
|
|
4
|
+
from sqlalchemy.dialects import postgresql as sqlalchemy_psql
|
|
5
|
+
from sqlalchemy.dialects import sqlite as sqlalchemy_sqlite
|
|
6
|
+
|
|
7
|
+
from core.auth_tokens.auth_token_invalidation_store import AuthTokenInvalidationStore
|
|
8
|
+
from core.exceptions import InternalServerErrorException
|
|
9
|
+
from core.store.database import Database
|
|
10
|
+
from core.store.database import DatabaseTable
|
|
11
|
+
|
|
12
|
+
# NOTE(krishan711): like LocksTable, this table ships with core-py. To include it in an app's alembic-tracked metadata
|
|
13
|
+
# (so autogenerate creates it), call `AuthTokenInvalidationsTable.to_metadata(appMetadata)` from the app's schema module.
|
|
14
|
+
AuthTokenInvalidationsMetadata = sqlalchemy.MetaData()
|
|
15
|
+
|
|
16
|
+
AuthTokenInvalidationsTable = sqlalchemy.Table(
|
|
17
|
+
'tbl_auth_token_invalidations',
|
|
18
|
+
AuthTokenInvalidationsMetadata,
|
|
19
|
+
sqlalchemy.Column(key='id', name='id', type_=sqlalchemy.Integer, autoincrement=True, primary_key=True, nullable=False),
|
|
20
|
+
sqlalchemy.Column(key='createdDate', name='created_date', type_=sqlalchemy.DateTime(timezone=True), nullable=False),
|
|
21
|
+
sqlalchemy.Column(key='key', name='key', type_=sqlalchemy.Text, nullable=False),
|
|
22
|
+
sqlalchemy.Column(key='expiryDate', name='expiry_date', type_=sqlalchemy.DateTime(timezone=True), nullable=False),
|
|
23
|
+
sqlalchemy.UniqueConstraint('key', name='tbl_auth_token_invalidations_ux_key'),
|
|
24
|
+
sqlalchemy.Index('tbl_auth_token_invalidations_idx_expiry_date', 'expiryDate'),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SqlAuthTokenInvalidationStore(AuthTokenInvalidationStore):
|
|
29
|
+
def __init__(self, database: Database, table: DatabaseTable = AuthTokenInvalidationsTable) -> None:
|
|
30
|
+
self.database = database
|
|
31
|
+
self.table = table
|
|
32
|
+
|
|
33
|
+
async def invalidate(self, key: str, lifetime: datetime.timedelta) -> bool:
|
|
34
|
+
async with self.database.create_transaction() as connection:
|
|
35
|
+
await self.database.execute(query=sqlalchemy.delete(self.table).where(self.table.c.expiryDate <= self.database.now()), connection=connection)
|
|
36
|
+
insertQuery = (
|
|
37
|
+
self._create_insert(dialectName=connection.dialect.name)
|
|
38
|
+
.values({self.table.c.createdDate: self.database.now(), self.table.c.key: key, self.table.c.expiryDate: self.database.now(seconds=lifetime.total_seconds())})
|
|
39
|
+
.on_conflict_do_nothing(index_elements=[self.table.c.key])
|
|
40
|
+
.returning(self.table.c.key)
|
|
41
|
+
)
|
|
42
|
+
result = await self.database.execute(query=insertQuery, connection=connection)
|
|
43
|
+
return result.first() is not None
|
|
44
|
+
|
|
45
|
+
async def is_invalidated(self, key: str) -> bool:
|
|
46
|
+
async with self.database.create_transaction() as connection:
|
|
47
|
+
query = sqlalchemy.select(self.table.c.key).where(self.table.c.key == key).where(self.table.c.expiryDate > self.database.now())
|
|
48
|
+
result = await self.database.execute(query=query, connection=connection)
|
|
49
|
+
return result.first() is not None
|
|
50
|
+
|
|
51
|
+
def _create_insert(self, dialectName: str) -> sqlalchemy_psql.Insert | sqlalchemy_sqlite.Insert:
|
|
52
|
+
if dialectName == 'postgresql':
|
|
53
|
+
return sqlalchemy_psql.insert(self.table)
|
|
54
|
+
if dialectName == 'sqlite':
|
|
55
|
+
return sqlalchemy_sqlite.insert(self.table)
|
|
56
|
+
raise InternalServerErrorException(message=f'SqlAuthTokenInvalidationStore does not support dialect: {dialectName}')
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
from core.exceptions import UnauthorizedException
|
|
7
|
+
from core.http.jwt import KibaJwt
|
|
8
|
+
from core.util import date_util
|
|
9
|
+
from core.util.typing_util import JsonObject
|
|
10
|
+
|
|
11
|
+
TOKEN_TYPE_KEY = 'tty'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# NOTE(krishan711): HS256 JWTs typed by tokenType so a token issued for one purpose can't be used for another. Each token
|
|
15
|
+
# has a tokenId, so pair it with an AuthTokenInvalidationStore to make a token single-use
|
|
16
|
+
class SignedTokenManager:
|
|
17
|
+
def __init__(self, secret: str, keyId: str) -> None:
|
|
18
|
+
self._secret = secret.encode('utf-8')
|
|
19
|
+
self.keyId = keyId
|
|
20
|
+
|
|
21
|
+
def create_token(self, tokenType: str, lifetime: datetime.timedelta, claims: JsonObject) -> str:
|
|
22
|
+
issueDate = date_util.datetime_from_now()
|
|
23
|
+
jwt = KibaJwt(
|
|
24
|
+
headerDict={KibaJwt.Key.ALGORITHM: 'HS256', KibaJwt.Key.TYPE: 'JWT', KibaJwt.Key.KEY_ID: self.keyId},
|
|
25
|
+
payloadDict={
|
|
26
|
+
**claims,
|
|
27
|
+
KibaJwt.Key.TOKEN_ID: str(uuid.uuid4()),
|
|
28
|
+
TOKEN_TYPE_KEY: tokenType,
|
|
29
|
+
KibaJwt.Key.ISSUE_DATE: int(issueDate.timestamp()),
|
|
30
|
+
KibaJwt.Key.EXPIRY_DATE: int((issueDate + lifetime).timestamp()),
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
jwt.signatureBytes = self._sign(jwt=jwt)
|
|
34
|
+
return jwt.to_string()
|
|
35
|
+
|
|
36
|
+
def validate_token(self, tokenString: str, tokenType: str) -> KibaJwt:
|
|
37
|
+
try:
|
|
38
|
+
jwt = KibaJwt.from_string(jwtString=tokenString)
|
|
39
|
+
except Exception as exception:
|
|
40
|
+
raise UnauthorizedException(message='INVALID_TOKEN') from exception
|
|
41
|
+
if not isinstance(jwt.headerDict, dict) or not isinstance(jwt.payloadDict, dict):
|
|
42
|
+
raise UnauthorizedException(message='INVALID_TOKEN')
|
|
43
|
+
if jwt.algorithm != 'HS256' or jwt.keyId != self.keyId or not hmac.compare_digest(jwt.signatureBytes, self._sign(jwt=jwt)):
|
|
44
|
+
raise UnauthorizedException(message='INVALID_TOKEN')
|
|
45
|
+
if jwt.payloadDict.get(TOKEN_TYPE_KEY) != tokenType:
|
|
46
|
+
raise UnauthorizedException(message='INVALID_TOKEN_TYPE')
|
|
47
|
+
expiryDate = jwt.expiryDate
|
|
48
|
+
if not expiryDate or expiryDate <= date_util.datetime_from_now():
|
|
49
|
+
raise UnauthorizedException(message='TOKEN_EXPIRED')
|
|
50
|
+
return jwt
|
|
51
|
+
|
|
52
|
+
def _sign(self, jwt: KibaJwt) -> bytes:
|
|
53
|
+
return hmac.new(self._secret, jwt.verificationString.encode('utf-8'), hashlib.sha256).digest()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from abc import abstractmethod
|
|
3
|
+
|
|
4
|
+
from core.mcp.model import McpUser
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class McpIdentityProvider(ABC):
|
|
8
|
+
@abstractmethod
|
|
9
|
+
def create_authorize_url(self, redirectUri: str, state: str) -> str: ...
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
async def authenticate_code(self, code: str, redirectUri: str) -> McpUser: ...
|
|
13
|
+
|
|
14
|
+
@abstractmethod
|
|
15
|
+
async def ensure_user_allowed(self, user: McpUser) -> None: ...
|