iatoolkit 2.83.0__tar.gz → 2.83.2__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.
- {iatoolkit-2.83.0/src/iatoolkit.egg-info → iatoolkit-2.83.2}/PKG-INFO +1 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/__init__.py +1 -1
- iatoolkit-2.83.2/src/iatoolkit/common/csrf_guard.py +139 -0
- iatoolkit-2.83.2/src/iatoolkit/common/rate_limiter.py +111 -0
- iatoolkit-2.83.2/src/iatoolkit/common/security_headers.py +125 -0
- iatoolkit-2.83.2/src/iatoolkit/common/user_errors.py +70 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/core.py +10 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/locales/en.yaml +4 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/locales/es.yaml +5 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/auth_service.py +46 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/profile_service.py +25 -9
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/categories_api_view.py +3 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/change_password_view.py +3 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/chat_context_preview_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/chat_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/configuration_api_view.py +4 -3
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/connectors_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/conversations_api_view.py +3 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/forgot_password_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/help_content_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/home_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/init_context_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/load_document_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/login_view.py +6 -3
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/memory_api_view.py +3 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/prompt_api_view.py +5 -4
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/prompt_context_preview_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/prompt_resource_api_view.py +3 -2
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/rag_api_view.py +8 -7
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/signup_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/user_feedback_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/users_api_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/verify_user_view.py +2 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2/src/iatoolkit.egg-info}/PKG-INFO +1 -1
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit.egg-info/SOURCES.txt +4 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/LICENSE +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/LICENSE_COMMUNITY.md +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/pyproject.toml +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/readme.md +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/setup.cfg +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/base_company.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/cli_commands.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/access.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/bridge_validation.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/company_paths.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/decision_types.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/exceptions.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/asset_storage.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/database_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/history_compaction_trigger.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/memory_compilation_trigger.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/secret_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/signup_policy_resolver.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/interfaces/web_search_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/memory_tools.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/model_registry.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/routes.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/search_terms.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/secret_resolver.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/session_manager.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/text_splitter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/url_safety.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/common/util.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/company_registry.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/llm_capabilities.yaml +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/conversation_title.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/history_compaction.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_compiler.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_correction.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_document_ingest.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_image_ingest.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_meeting_ingest.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents/memory_question_review.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_agents_pack.yaml +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/channel_business_identity.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/channel_conversation_continuity.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/channel_response_style.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/chart_output.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/chat_state_rules.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/chat_user_profile.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/core_identity.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/email_output.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/file_download_output.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/html_structures.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/links_documents.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/memory_usage.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/multimodal_basics.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/output_basics.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/presentation_formatting.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_aggregation_scope.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_casting.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_core.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_jsonb.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_mysql_casting.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_mysql_json.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_redshift_basics.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/sql_redshift_types.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts/tool_html_passthrough.prompt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_prompts_pack.yaml +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/config/system_tools_pack.yaml +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/brevo_mail_app.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/call_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/file_connector.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/file_connector_factory.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/google_cloud_storage_connector.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/google_drive_connector.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/local_file_connector.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/connectors/s3_connector.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/google_auth_client.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/google_chat_app.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/inference_embeddings_client.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/inference_handler.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/jina_embeddings_client.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_gateway_resolver.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/anthropic_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/attachment_mime.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/deepseek_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/gemini_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/openai_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/openai_compatible_chat_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_providers/openrouter_adapter.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_proxy.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/llm_response.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/openrouter_decision_client.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/infra/redis_session_manager.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/advisory_lock.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/api_key_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/bridge_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/conversation_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/database_manager.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/document_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/env_secret_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/filesystem_asset_repository.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/knowledge_wiki_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/llm_query_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/mcp_token_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/memory_question_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/memory_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/memory_usage_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/models.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/profile_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/prompt_resource_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/sql_dataset_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/sql_source_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/repositories/vs_repo.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/runtime_logging.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/api_key_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/attachment_policy_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/branding_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/chart_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/chat_stream.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/company_context_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/configuration_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/context_builder_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/conversation_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/decision_attachments.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/decision_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/dispatcher_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/embedding_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/excel_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/file_processor_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/history_compaction_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/history_manager_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/http_tool_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/i18n_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/inference_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/jwt_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/knowledge_base_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/language_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/license_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/llm_client_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/mail_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/markdown_wiki_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/mcp_token_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_compiler_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_lookup_policy_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_question_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_sources.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_usage_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/memory_wiki_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/noop_history_compaction_trigger.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/noop_memory_compilation_trigger.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/operator_identity_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/contracts.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/image_normalizer.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/parsing_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/pdf_ocr_detection.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/provider_factory.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/provider_resolver.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/providers/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/providers/basic_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/providers/docling_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/parsers/validator.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/pdf_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/prompt_resource_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/prompt_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/query_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/resource_access_scope.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/signup_guard_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/signup_policy_resolver.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/sql_catalog_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/sql_dataset_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/sql_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/sql_source_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/storage_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/structured_output_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/system_agent_catalog.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/system_agent_runner.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/system_prompt_catalog.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/system_tools.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/telemetry_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/tenant_wiki_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/tool_output_contract.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/tool_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/user_feedback_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/user_session_context_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/visual_kb_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/visual_tool_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/warmup_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/web_search/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/web_search/provider_factory.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/web_search/providers/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/web_search/providers/brave_provider.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/web_search_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/services/wiki_page_index_service.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/images/favicon.ico +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/images/favicon.png +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/images/fernando.jpeg +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/images/iatoolkit_core.png +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/images/iatoolkit_logo.png +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_charts.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_conversations.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_feedback_button.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_filepond.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_header_navigation.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_help_content.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_logout_button.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_main.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_memory_button.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_model_selector.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_onboarding_button.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_prompt_manager.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/js/chat_stream.js +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/account.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/chat_iatoolkit.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/chat_modal.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/chat_public.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/documents.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/landing_page.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/llm_output.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/onboarding.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/static/styles/wiki_page.css +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/_chat_header.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/_company_header.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/_login_widget.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/account.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/base.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/change_password.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/chat.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/chat_memory_modal.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/chat_modals.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/error.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/forgot_password.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/home_hosted_default.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/invitation_invalid.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/login_global.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/memory/wiki_schema.md +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/pdf/base.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/pdf/letter.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/pdf/report.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/pdf/simple.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/signup.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/templates/wiki_page.html +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/__init__.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/account_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/api_key_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/base_login_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/embedding_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/llmquery_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/llmquery_stream_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/logout_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/profile_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/root_redirect_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/static_page_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/tool_api_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit/views/wiki_page_view.py +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit.egg-info/dependency_links.txt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit.egg-info/requires.txt +0 -0
- {iatoolkit-2.83.0 → iatoolkit-2.83.2}/src/iatoolkit.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Cross-site request forgery guard (BL-030, PR-8).
|
|
8
|
+
|
|
9
|
+
A request that changes something (POST, PUT, PATCH, DELETE), carries the session
|
|
10
|
+
cookie and no Authorization header is accepted only when the browser says it
|
|
11
|
+
comes from this same site:
|
|
12
|
+
|
|
13
|
+
1. `Sec-Fetch-Site: same-origin` (or `none`, typed by the person) is enough; every
|
|
14
|
+
current browser sends it.
|
|
15
|
+
2. Otherwise its `Origin`, or the origin of its `Referer`, must be this host, one
|
|
16
|
+
listed in IAT_CSRF_TRUSTED_ORIGINS, or one a company declares in `cors_origin`:
|
|
17
|
+
CORS already lets those call with credentials, and a portal that serves the chat
|
|
18
|
+
(Maxxa's) calls back from there with the session cookie.
|
|
19
|
+
3. A request with neither signal is not from a browser, and a forgery needs a
|
|
20
|
+
browser, so it passes.
|
|
21
|
+
|
|
22
|
+
No client changes are needed: the chat, the admin console, tenant apps and forms
|
|
23
|
+
already send these headers, and a page embedded in another site's iframe still
|
|
24
|
+
calls its own origin. Calls with an Authorization header (API keys, bearer tokens)
|
|
25
|
+
and requests without the session cookie are out of scope: nothing ambient to abuse.
|
|
26
|
+
|
|
27
|
+
Configuration (config dict or environment):
|
|
28
|
+
- IAT_CSRF_MODE: "enforce" (default), "report" (log what would be blocked) or "off".
|
|
29
|
+
- IAT_CSRF_TRUSTED_ORIGINS: other origins allowed to post with the session,
|
|
30
|
+
space separated, e.g. "https://portal.example.com".
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
import logging
|
|
34
|
+
import os
|
|
35
|
+
from urllib.parse import urlsplit
|
|
36
|
+
|
|
37
|
+
from flask import Flask, jsonify, request
|
|
38
|
+
|
|
39
|
+
UNSAFE_METHODS = frozenset({"POST", "PUT", "PATCH", "DELETE"})
|
|
40
|
+
SAME_SITE_SIGNALS = frozenset({"same-origin", "none"})
|
|
41
|
+
CSRF_MODES = ("enforce", "report", "off")
|
|
42
|
+
# Endpoints a browser reaches across sites on purpose and that change nothing a
|
|
43
|
+
# session owns.
|
|
44
|
+
EXEMPT_ENDPOINTS = frozenset({"csp_report"})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _setting(app: Flask, config: dict | None, key: str, default: str) -> str:
|
|
48
|
+
value = config.get(key) if config else None
|
|
49
|
+
if value is None:
|
|
50
|
+
value = app.config.get(key)
|
|
51
|
+
if value is None:
|
|
52
|
+
value = os.getenv(key, default)
|
|
53
|
+
return str(value or default).strip()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _origin_of(url: str | None) -> str | None:
|
|
57
|
+
value = str(url or "").strip()
|
|
58
|
+
if not value or value == "null":
|
|
59
|
+
return None
|
|
60
|
+
parts = urlsplit(value)
|
|
61
|
+
if not parts.scheme or not parts.netloc:
|
|
62
|
+
return None
|
|
63
|
+
return f"{parts.scheme}://{parts.netloc}".lower()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def csrf_verdict(*, method: str, has_authorization: bool, has_session_cookie: bool, endpoint: str | None,
|
|
67
|
+
sec_fetch_site: str | None, origin: str | None, referer: str | None,
|
|
68
|
+
own_origin: str, trusted_origins: frozenset[str]) -> tuple[bool, str]:
|
|
69
|
+
"""(allowed, reason). Pure, so every rule can be tested on its own."""
|
|
70
|
+
if method.upper() not in UNSAFE_METHODS:
|
|
71
|
+
return True, "safe_method"
|
|
72
|
+
if has_authorization:
|
|
73
|
+
return True, "authorization_header"
|
|
74
|
+
if not has_session_cookie:
|
|
75
|
+
return True, "no_session_cookie"
|
|
76
|
+
if endpoint in EXEMPT_ENDPOINTS:
|
|
77
|
+
return True, "exempt_endpoint"
|
|
78
|
+
|
|
79
|
+
fetch_site = str(sec_fetch_site or "").strip().lower()
|
|
80
|
+
if fetch_site in SAME_SITE_SIGNALS:
|
|
81
|
+
return True, "same_origin_fetch"
|
|
82
|
+
|
|
83
|
+
source = _origin_of(origin) or _origin_of(referer)
|
|
84
|
+
if source:
|
|
85
|
+
if source == own_origin.lower() or source in trusted_origins:
|
|
86
|
+
return True, "trusted_origin"
|
|
87
|
+
return False, "foreign_origin"
|
|
88
|
+
if fetch_site: # cross-site or same-site with no origin to trust
|
|
89
|
+
return False, f"sec_fetch_site_{fetch_site}"
|
|
90
|
+
return True, "no_browser_signal"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def install_csrf_guard(app: Flask, config: dict | None = None) -> None:
|
|
94
|
+
if app.config.get("_IATOOLKIT_CSRF_GUARD_INSTALLED"):
|
|
95
|
+
return
|
|
96
|
+
app.config["_IATOOLKIT_CSRF_GUARD_INSTALLED"] = True
|
|
97
|
+
|
|
98
|
+
mode = _setting(app, config, "IAT_CSRF_MODE", "enforce").lower()
|
|
99
|
+
if mode not in CSRF_MODES:
|
|
100
|
+
logging.warning("IAT_CSRF_MODE=%s is not one of %s; using 'enforce'.", mode, ", ".join(CSRF_MODES))
|
|
101
|
+
mode = "enforce"
|
|
102
|
+
if mode == "off":
|
|
103
|
+
logging.warning("CSRF guard is off (IAT_CSRF_MODE=off).")
|
|
104
|
+
return
|
|
105
|
+
trusted = frozenset(
|
|
106
|
+
origin for origin in (_origin_of(item) for item in
|
|
107
|
+
_setting(app, config, "IAT_CSRF_TRUSTED_ORIGINS", "").split())
|
|
108
|
+
if origin)
|
|
109
|
+
|
|
110
|
+
@app.before_request
|
|
111
|
+
def _csrf_guard():
|
|
112
|
+
cookie_name = app.config.get("SESSION_COOKIE_NAME") or "session"
|
|
113
|
+
cors_origins = frozenset(
|
|
114
|
+
origin for origin in (_origin_of(item) for item in app.config.get("IAT_CORS_ORIGINS") or [])
|
|
115
|
+
if origin)
|
|
116
|
+
allowed, reason = csrf_verdict(
|
|
117
|
+
method=request.method,
|
|
118
|
+
has_authorization=bool(request.headers.get("Authorization")),
|
|
119
|
+
has_session_cookie=cookie_name in request.cookies,
|
|
120
|
+
endpoint=request.endpoint,
|
|
121
|
+
sec_fetch_site=request.headers.get("Sec-Fetch-Site"),
|
|
122
|
+
origin=request.headers.get("Origin"),
|
|
123
|
+
referer=request.headers.get("Referer"),
|
|
124
|
+
own_origin=f"{request.scheme}://{request.host}",
|
|
125
|
+
trusted_origins=trusted | cors_origins,
|
|
126
|
+
)
|
|
127
|
+
if allowed:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
first_segment = request.path.strip("/").split("/", 1)[0][:40]
|
|
131
|
+
logging.warning(
|
|
132
|
+
"event=csrf_%s method=%s path=/%s reason=%s origin=%s sec_fetch_site=%s",
|
|
133
|
+
"blocked" if mode == "enforce" else "would_block", request.method, first_segment, reason,
|
|
134
|
+
_origin_of(request.headers.get("Origin")) or _origin_of(request.headers.get("Referer")),
|
|
135
|
+
request.headers.get("Sec-Fetch-Site"),
|
|
136
|
+
)
|
|
137
|
+
if mode == "report":
|
|
138
|
+
return None
|
|
139
|
+
return jsonify({"error": "forbidden", "error_message": "Cross-site request refused."}), 403
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Rate limits on the doors that guess credentials (BL-030, PR-10).
|
|
8
|
+
|
|
9
|
+
Fixed windows in Redis, per client IP and, where there is one, per account. A
|
|
10
|
+
limit is a (max_hits, window_seconds) pair; `over_limit` counts one hit and says
|
|
11
|
+
whether it went past the limit. Failures are counted with `record_failure`, and
|
|
12
|
+
`clear` forgets them after a success.
|
|
13
|
+
|
|
14
|
+
Fails open: if Redis cannot answer, nothing is blocked. Sessions live in the same
|
|
15
|
+
Redis, so with it down there is no login to protect anyway, and a limiter that
|
|
16
|
+
locked everybody out would turn a Redis hiccup into an outage.
|
|
17
|
+
|
|
18
|
+
IAT_RATE_LIMITS=off turns every limit off (automated end-to-end tests).
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import hashlib
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
from iatoolkit.infra.redis_session_manager import RedisSessionManager
|
|
26
|
+
|
|
27
|
+
KEY_PREFIX = "iat:ratelimit"
|
|
28
|
+
|
|
29
|
+
# (max hits, window in seconds)
|
|
30
|
+
LOGIN_FAILURES_PER_ACCOUNT = (10, 15 * 60)
|
|
31
|
+
LOGIN_ATTEMPTS_PER_IP = (50, 15 * 60)
|
|
32
|
+
PASSWORD_RESET_REQUESTS_PER_ACCOUNT = (5, 60 * 60)
|
|
33
|
+
PASSWORD_RESET_REQUESTS_PER_IP = (20, 60 * 60)
|
|
34
|
+
PASSWORD_CHANGE_ATTEMPTS_PER_IP = (20, 15 * 60)
|
|
35
|
+
TOKEN_REDEEMS_PER_IP = (60, 60)
|
|
36
|
+
INVALID_API_KEYS_PER_IP = (30, 60)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def enabled() -> bool:
|
|
40
|
+
return os.getenv("IAT_RATE_LIMITS", "on").strip().lower() not in ("off", "false", "0")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _key(bucket: str, identity: str) -> str:
|
|
44
|
+
# Hashed so emails and IPs are not readable from Redis keys.
|
|
45
|
+
digest = hashlib.sha256(str(identity or "").strip().lower().encode("utf-8")).hexdigest()[:32]
|
|
46
|
+
return f"{KEY_PREFIX}:{bucket}:{digest}"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _incr(key: str, window_seconds: int) -> int:
|
|
50
|
+
try:
|
|
51
|
+
pipe = RedisSessionManager.pipeline()
|
|
52
|
+
pipe.incr(key)
|
|
53
|
+
pipe.ttl(key)
|
|
54
|
+
count, ttl = pipe.execute()
|
|
55
|
+
if ttl is None or int(ttl) < 0:
|
|
56
|
+
RedisSessionManager.pipeline().expire(key, window_seconds).execute()
|
|
57
|
+
return int(count)
|
|
58
|
+
except Exception as exc:
|
|
59
|
+
logging.warning("rate limiter unavailable, letting the request through (%s)", exc)
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _peek(key: str) -> int | None:
|
|
64
|
+
"""The current count, or None when Redis cannot answer (which never blocks)."""
|
|
65
|
+
try:
|
|
66
|
+
return int(RedisSessionManager.get(key, "0") or 0)
|
|
67
|
+
except Exception as exc:
|
|
68
|
+
logging.warning("rate limiter unavailable, letting the request through (%s)", exc)
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def over_limit(bucket: str, identity: str | None, limit: tuple[int, int]) -> bool:
|
|
73
|
+
"""Counts one hit for `identity` and says whether it went past `limit`."""
|
|
74
|
+
if not identity or not enabled():
|
|
75
|
+
return False
|
|
76
|
+
max_hits, window = limit
|
|
77
|
+
over = _incr(_key(bucket, identity), window) > max_hits
|
|
78
|
+
if over:
|
|
79
|
+
logging.warning("event=rate_limited bucket=%s", bucket)
|
|
80
|
+
return over
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def is_blocked(bucket: str, identity: str | None, limit: tuple[int, int]) -> bool:
|
|
84
|
+
"""Whether `identity` already used up `limit`, without counting a hit."""
|
|
85
|
+
if not identity or not enabled():
|
|
86
|
+
return False
|
|
87
|
+
count = _peek(_key(bucket, identity))
|
|
88
|
+
blocked = count is not None and count >= limit[0]
|
|
89
|
+
if blocked:
|
|
90
|
+
logging.warning("event=rate_limited bucket=%s", bucket)
|
|
91
|
+
return blocked
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def record_failure(bucket: str, identity: str | None, limit: tuple[int, int]) -> None:
|
|
95
|
+
if identity and enabled():
|
|
96
|
+
_incr(_key(bucket, identity), limit[1])
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def clear(bucket: str, identity: str | None) -> None:
|
|
100
|
+
if not identity:
|
|
101
|
+
return
|
|
102
|
+
try:
|
|
103
|
+
RedisSessionManager.remove(_key(bucket, identity))
|
|
104
|
+
except Exception as exc:
|
|
105
|
+
logging.warning("rate limiter unavailable (%s)", exc)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def client_ip(request) -> str | None:
|
|
109
|
+
"""The real client IP; same rules as the signup guard (Cloudflare, proxy hops)."""
|
|
110
|
+
from iatoolkit.services.signup_guard_service import SignupGuardService
|
|
111
|
+
return SignupGuardService.client_ip(request)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Security headers on every response (BL-030, PR-7).
|
|
8
|
+
|
|
9
|
+
Always on: HSTS on HTTPS requests, `X-Content-Type-Options: nosniff` and a
|
|
10
|
+
`Referrer-Policy` that keeps paths (which can carry tokens) out of other sites.
|
|
11
|
+
|
|
12
|
+
The Content-Security-Policy, `frame-ancestors` included, starts in report-only
|
|
13
|
+
mode: browsers report what the policy would block to `/csp-report`, which logs it,
|
|
14
|
+
and nothing is blocked. That tells, in production, which portals embed IAToolkit
|
|
15
|
+
and which outside resources pages really use, before the policy is enforced.
|
|
16
|
+
|
|
17
|
+
Configuration (config dict or environment):
|
|
18
|
+
- IAT_CSP_MODE: "report" (default), "enforce" or "off".
|
|
19
|
+
- IAT_FRAME_ANCESTORS: who may embed the pages, space separated
|
|
20
|
+
(default "'self'"), e.g. "'self' https://portal.example.com".
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
import logging
|
|
25
|
+
import os
|
|
26
|
+
from urllib.parse import urlsplit
|
|
27
|
+
|
|
28
|
+
from flask import Flask, request
|
|
29
|
+
|
|
30
|
+
CSP_REPORT_PATH = "/csp-report"
|
|
31
|
+
CSP_MODES = ("report", "enforce", "off")
|
|
32
|
+
DEFAULT_FRAME_ANCESTORS = "'self'"
|
|
33
|
+
# Sources the templates load today: the CDNs for scripts, styles and fonts, Google
|
|
34
|
+
# Tag Manager on the public site and Google Fonts.
|
|
35
|
+
CDN_SOURCES = "https://cdn.jsdelivr.net https://cdnjs.cloudflare.com https://unpkg.com https://code.jquery.com"
|
|
36
|
+
HSTS_VALUE = "max-age=31536000"
|
|
37
|
+
MAX_REPORT_BYTES = 16 * 1024
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def build_csp(frame_ancestors: str) -> str:
|
|
41
|
+
directives = [
|
|
42
|
+
"default-src 'self'",
|
|
43
|
+
f"script-src 'self' 'unsafe-inline' {CDN_SOURCES} https://www.googletagmanager.com",
|
|
44
|
+
f"style-src 'self' 'unsafe-inline' {CDN_SOURCES} https://fonts.googleapis.com",
|
|
45
|
+
f"font-src 'self' data: {CDN_SOURCES} https://fonts.gstatic.com",
|
|
46
|
+
"img-src 'self' data: blob: https:",
|
|
47
|
+
"connect-src 'self'",
|
|
48
|
+
"frame-src 'self'",
|
|
49
|
+
f"frame-ancestors {frame_ancestors}",
|
|
50
|
+
"object-src 'none'",
|
|
51
|
+
"base-uri 'self'",
|
|
52
|
+
"form-action 'self'",
|
|
53
|
+
f"report-uri {CSP_REPORT_PATH}",
|
|
54
|
+
]
|
|
55
|
+
return "; ".join(directives)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _setting(app: Flask, config: dict, key: str, default: str) -> str:
|
|
59
|
+
value = config.get(key) if config else None
|
|
60
|
+
if value is None:
|
|
61
|
+
value = app.config.get(key)
|
|
62
|
+
if value is None:
|
|
63
|
+
value = os.getenv(key, default)
|
|
64
|
+
return str(value or default).strip()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def install_security_headers(app: Flask, config: dict | None = None) -> None:
|
|
68
|
+
if app.config.get("_IATOOLKIT_SECURITY_HEADERS_INSTALLED"):
|
|
69
|
+
return
|
|
70
|
+
app.config["_IATOOLKIT_SECURITY_HEADERS_INSTALLED"] = True
|
|
71
|
+
|
|
72
|
+
mode = _setting(app, config, "IAT_CSP_MODE", "report").lower()
|
|
73
|
+
if mode not in CSP_MODES:
|
|
74
|
+
logging.warning("IAT_CSP_MODE=%s is not one of %s; using 'report'.", mode, ", ".join(CSP_MODES))
|
|
75
|
+
mode = "report"
|
|
76
|
+
frame_ancestors = _setting(app, config, "IAT_FRAME_ANCESTORS", DEFAULT_FRAME_ANCESTORS)
|
|
77
|
+
csp = build_csp(frame_ancestors)
|
|
78
|
+
csp_header = {"report": "Content-Security-Policy-Report-Only",
|
|
79
|
+
"enforce": "Content-Security-Policy"}.get(mode)
|
|
80
|
+
|
|
81
|
+
@app.after_request
|
|
82
|
+
def _security_headers(response):
|
|
83
|
+
headers = response.headers
|
|
84
|
+
headers.setdefault("X-Content-Type-Options", "nosniff")
|
|
85
|
+
headers.setdefault("Referrer-Policy", "strict-origin-when-cross-origin")
|
|
86
|
+
if request.is_secure:
|
|
87
|
+
headers.setdefault("Strict-Transport-Security", HSTS_VALUE)
|
|
88
|
+
if csp_header and "Content-Security-Policy" not in headers \
|
|
89
|
+
and "Content-Security-Policy-Report-Only" not in headers:
|
|
90
|
+
headers[csp_header] = csp
|
|
91
|
+
return response
|
|
92
|
+
|
|
93
|
+
app.add_url_rule(CSP_REPORT_PATH, "csp_report", _csp_report, methods=["POST"])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _where(uri) -> str:
|
|
97
|
+
"""Origin and first path segment only: full URLs can carry tokens
|
|
98
|
+
(finalize/<token>, links with codes), which must not reach the logs."""
|
|
99
|
+
value = str(uri or "").strip()
|
|
100
|
+
if not value or "://" not in value:
|
|
101
|
+
return value[:40] # keywords such as 'inline' or 'eval'
|
|
102
|
+
parts = urlsplit(value)
|
|
103
|
+
first = parts.path.strip("/").split("/", 1)[0]
|
|
104
|
+
return f"{parts.scheme}://{parts.netloc}/{first[:40]}"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _csp_report():
|
|
108
|
+
"""Logs what the policy reported; always answers 204 and never fails."""
|
|
109
|
+
try:
|
|
110
|
+
if (request.content_length or 0) > MAX_REPORT_BYTES:
|
|
111
|
+
return "", 204
|
|
112
|
+
payload = json.loads(request.get_data(cache=False, as_text=True) or "{}")
|
|
113
|
+
reports = payload if isinstance(payload, list) else [payload]
|
|
114
|
+
for item in reports[:10]:
|
|
115
|
+
body = item.get("csp-report") or item.get("body") or {}
|
|
116
|
+
logging.warning(
|
|
117
|
+
"event=csp_violation directive=%s blocked=%s document=%s disposition=%s",
|
|
118
|
+
body.get("effective-directive") or body.get("effectiveDirective") or body.get("violated-directive"),
|
|
119
|
+
_where(body.get("blocked-uri") or body.get("blockedURL")),
|
|
120
|
+
_where(body.get("document-uri") or body.get("documentURL")),
|
|
121
|
+
body.get("disposition"),
|
|
122
|
+
)
|
|
123
|
+
except Exception as exc: # a malformed report is not worth an error
|
|
124
|
+
logging.debug("Ignoring an unreadable CSP report: %s", exc)
|
|
125
|
+
return "", 204
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Unexpected errors as a person sees them.
|
|
8
|
+
|
|
9
|
+
The text of an exception can carry SQL, table and column names, file paths or
|
|
10
|
+
configuration: shown to the user it maps the system for anyone probing it. So the
|
|
11
|
+
person gets a generic message with a short reference, and the exception goes to the
|
|
12
|
+
log under that same reference, where support can find it (BL-030, gap #24).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import logging
|
|
16
|
+
import secrets
|
|
17
|
+
|
|
18
|
+
GENERAL_KEY = "errors.general.unexpected_error_ref"
|
|
19
|
+
PAGE_KEY = "errors.templates.processing_error"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def new_error_ref() -> str:
|
|
23
|
+
"""A short reference that ties what the person sees to the log line."""
|
|
24
|
+
return secrets.token_hex(4)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def unexpected_error_message(i18n_service, exc: BaseException, *, where: str, key: str = GENERAL_KEY) -> str:
|
|
28
|
+
"""Logs `exc` with a reference and returns the translated generic message for it.
|
|
29
|
+
|
|
30
|
+
`key` must be a translation that takes `{ref}` and never shows the exception.
|
|
31
|
+
"""
|
|
32
|
+
ref = new_error_ref()
|
|
33
|
+
logging.error("Unexpected error in %s [ref=%s]: %s", where, ref, exc, exc_info=exc)
|
|
34
|
+
return i18n_service.t(key, ref=ref)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Domain errors whose message is written for the person: shown as they are. Matched
|
|
38
|
+
# by name so the core and Enterprise exception classes both qualify.
|
|
39
|
+
USER_FACING_ERROR_TYPES = frozenset({
|
|
40
|
+
"INVALID_PARAMETER", "MISSING_PARAMETER", "PARAM_NOT_FILLED", "PERMISSION", "EXIST",
|
|
41
|
+
"DOCUMENT_NOT_FOUND", "NOT_FOUND", "TASK_NOT_FOUND", "INVALID_NAME", "DUPLICATE_ENTRY",
|
|
42
|
+
"INVALID_OPERATION", "INVALID_STATE", "INVALID_USER", "FILE_FORMAT_ERROR", "INVALID_SQL",
|
|
43
|
+
})
|
|
44
|
+
INTERNAL_KEY = "errors.general.internal_error_ref"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_user_facing(exc: BaseException) -> bool:
|
|
48
|
+
error_type = getattr(getattr(exc, "error_type", None), "name", None)
|
|
49
|
+
if error_type is not None:
|
|
50
|
+
return error_type in USER_FACING_ERROR_TYPES
|
|
51
|
+
return type(exc) is ValueError # validation raised by our own code
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def public_error_text(exc: BaseException, where: str = "") -> str:
|
|
55
|
+
"""The text an HTTP response may carry for `exc`.
|
|
56
|
+
|
|
57
|
+
A domain error written for the person keeps its message. Anything else (a
|
|
58
|
+
database, library or system error) goes to the log under a reference, and the
|
|
59
|
+
response says only "internal error (reference …)" (BL-030, gap #24).
|
|
60
|
+
"""
|
|
61
|
+
if is_user_facing(exc):
|
|
62
|
+
return str(exc)
|
|
63
|
+
ref = new_error_ref()
|
|
64
|
+
logging.error("Unexpected error in %s [ref=%s]: %s", where or "request", ref, exc, exc_info=exc)
|
|
65
|
+
try:
|
|
66
|
+
from iatoolkit.core import current_iatoolkit
|
|
67
|
+
from iatoolkit.services.i18n_service import I18nService
|
|
68
|
+
return current_iatoolkit().get_injector().get(I18nService).t(INTERNAL_KEY, ref=ref)
|
|
69
|
+
except Exception:
|
|
70
|
+
return f"internal error (reference {ref})"
|
|
@@ -25,6 +25,8 @@ import threading
|
|
|
25
25
|
|
|
26
26
|
from iatoolkit import __version__ as IATOOLKIT_VERSION
|
|
27
27
|
from iatoolkit.runtime_logging import configure_runtime_logging, install_flask_request_logging
|
|
28
|
+
from iatoolkit.common.security_headers import install_security_headers
|
|
29
|
+
from iatoolkit.common.csrf_guard import install_csrf_guard
|
|
28
30
|
from iatoolkit.services.configuration_service import ConfigurationService
|
|
29
31
|
|
|
30
32
|
# global variable for the unique instance of IAToolkit
|
|
@@ -324,6 +326,11 @@ class IAToolkit:
|
|
|
324
326
|
# 2. ProxyFix para no tener problemas con iframes y rutas
|
|
325
327
|
self.app.wsgi_app = ProxyFix(self.app.wsgi_app, x_proto=1)
|
|
326
328
|
|
|
329
|
+
# Security headers on every response; the CSP starts in report-only (BL-030).
|
|
330
|
+
install_security_headers(self.app, self.config)
|
|
331
|
+
# Refuses cross-site requests that ride on the session cookie (BL-030).
|
|
332
|
+
install_csrf_guard(self.app, self.config)
|
|
333
|
+
|
|
327
334
|
# Configuración para tokenizers en desarrollo
|
|
328
335
|
if flask_env == 'dev':
|
|
329
336
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
@@ -398,6 +405,9 @@ class IAToolkit:
|
|
|
398
405
|
extra_origins += cors_origin
|
|
399
406
|
|
|
400
407
|
all_origins = default_origins + extra_origins
|
|
408
|
+
# The same origins may post with the session cookie: the CSRF guard trusts
|
|
409
|
+
# them (BL-030). Maxxa's portal serves the chat and calls back this way.
|
|
410
|
+
self.app.config['IAT_CORS_ORIGINS'] = list(all_origins)
|
|
401
411
|
|
|
402
412
|
CORS(self.app,
|
|
403
413
|
supports_credentials=True,
|
|
@@ -2870,6 +2870,7 @@ errors:
|
|
|
2870
2870
|
model_denied: "You do not have access to the model {model}."
|
|
2871
2871
|
timeout: "timeout expired."
|
|
2872
2872
|
auth:
|
|
2873
|
+
too_many_attempts: "Too many attempts. Wait a few minutes and try again."
|
|
2873
2874
|
invalid_password: "The provided password is incorrect."
|
|
2874
2875
|
user_not_found: "A user with that email address was not found."
|
|
2875
2876
|
google_account_requires_google_login: "This account uses Google sign-in. Continue with Google to log in."
|
|
@@ -2898,9 +2899,11 @@ errors:
|
|
|
2898
2899
|
company_not_found: "Company not found."
|
|
2899
2900
|
home_template_not_found: "The home page template for the company '{company_short_name}' is not configured."
|
|
2900
2901
|
template_not_found: "Template not found: '{template_name}'."
|
|
2901
|
-
processing_error: "
|
|
2902
|
+
processing_error: "We could not load this page. If the problem persists, contact support with reference {ref}."
|
|
2902
2903
|
general:
|
|
2903
2904
|
unexpected_error: "An unexpected error has occurred. Please contact support."
|
|
2905
|
+
unexpected_error_ref: "An unexpected error has occurred. If the problem persists, contact support with reference {ref}."
|
|
2906
|
+
internal_error_ref: "internal error (reference {ref})"
|
|
2904
2907
|
unsupported_language: "The selected language is not supported."
|
|
2905
2908
|
signup:
|
|
2906
2909
|
company_not_found: "The company {company_short_name} does not exist."
|
|
@@ -2887,6 +2887,7 @@ errors:
|
|
|
2887
2887
|
|
|
2888
2888
|
|
|
2889
2889
|
auth:
|
|
2890
|
+
too_many_attempts: "Demasiados intentos. Espera unos minutos e inténtalo de nuevo."
|
|
2890
2891
|
invalid_password: "La contraseña proporcionada es incorrecta."
|
|
2891
2892
|
user_not_found: "No se encontró un usuario con ese correo."
|
|
2892
2893
|
google_account_requires_google_login: "Esta cuenta usa acceso con Google. Continúa con Google para iniciar sesión."
|
|
@@ -2915,11 +2916,13 @@ errors:
|
|
|
2915
2916
|
templates:
|
|
2916
2917
|
company_not_found: "Empresa no encontrada."
|
|
2917
2918
|
home_template_not_found: "La plantilla de la página de inicio para la empresa '{company_short_name}' no está configurada."
|
|
2918
|
-
processing_error: "
|
|
2919
|
+
processing_error: "No pudimos cargar esta página. Si el problema persiste, contacta a soporte e indica la referencia {ref}."
|
|
2919
2920
|
template_not_found: "No se encontro el template: '{template_name}'."
|
|
2920
2921
|
|
|
2921
2922
|
general:
|
|
2922
|
-
unexpected_error: "Ha ocurrido un error inesperado
|
|
2923
|
+
unexpected_error: "Ha ocurrido un error inesperado. Si el problema persiste, contacta a soporte."
|
|
2924
|
+
unexpected_error_ref: "Ha ocurrido un error inesperado. Si el problema persiste, contacta a soporte e indica la referencia {ref}."
|
|
2925
|
+
internal_error_ref: "error interno (referencia {ref})"
|
|
2923
2926
|
unsupported_language: "El idioma seleccionado no es válido."
|
|
2924
2927
|
signup:
|
|
2925
2928
|
company_not_found: "La empresa {company_short_name} no existe."
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
#
|
|
4
4
|
# IAToolkit is open source software.
|
|
5
5
|
|
|
6
|
-
from flask import request
|
|
6
|
+
from flask import request, has_request_context
|
|
7
7
|
from injector import inject
|
|
8
|
+
from iatoolkit.common import rate_limiter
|
|
8
9
|
from iatoolkit.services.profile_service import ProfileService
|
|
9
10
|
from iatoolkit.services.api_key_service import ApiKeyService
|
|
10
11
|
from iatoolkit.services.jwt_service import JWTService
|
|
@@ -45,6 +46,10 @@ class AuthService:
|
|
|
45
46
|
|
|
46
47
|
def login_local_user(self, company_short_name: str, email: str, password: str) -> dict:
|
|
47
48
|
# try to autenticate a local user, register the event and return the result
|
|
49
|
+
limited = self._login_rate_limited(company_short_name, email)
|
|
50
|
+
if limited:
|
|
51
|
+
return limited
|
|
52
|
+
|
|
48
53
|
auth_response = self.profile_service.login(
|
|
49
54
|
company_short_name=company_short_name,
|
|
50
55
|
email=email,
|
|
@@ -52,6 +57,7 @@ class AuthService:
|
|
|
52
57
|
)
|
|
53
58
|
|
|
54
59
|
if not auth_response.get('success'):
|
|
60
|
+
rate_limiter.record_failure('login_account', email, rate_limiter.LOGIN_FAILURES_PER_ACCOUNT)
|
|
55
61
|
self.log_access(
|
|
56
62
|
company_short_name=company_short_name,
|
|
57
63
|
user_identifier=email,
|
|
@@ -60,6 +66,7 @@ class AuthService:
|
|
|
60
66
|
reason_code='INVALID_CREDENTIALS',
|
|
61
67
|
)
|
|
62
68
|
else:
|
|
69
|
+
rate_limiter.clear('login_account', email)
|
|
63
70
|
self.log_access(
|
|
64
71
|
company_short_name=company_short_name,
|
|
65
72
|
auth_type='local',
|
|
@@ -71,6 +78,9 @@ class AuthService:
|
|
|
71
78
|
|
|
72
79
|
def redeem_token_for_session(self, company_short_name: str, token: str) -> dict:
|
|
73
80
|
# redeem a token for a session, register the event and return the result
|
|
81
|
+
if rate_limiter.over_limit('redeem_ip', self._client_ip(), rate_limiter.TOKEN_REDEEMS_PER_IP):
|
|
82
|
+
return self._refuse_redeem(company_short_name, 'RATE_LIMITED')
|
|
83
|
+
|
|
74
84
|
payload = self.jwt_service.validate_chat_jwt(token)
|
|
75
85
|
|
|
76
86
|
if not payload:
|
|
@@ -111,6 +121,27 @@ class AuthService:
|
|
|
111
121
|
)
|
|
112
122
|
return {'success': False, 'error': self.i18n_service.t('errors.auth.session_creation_failed')}
|
|
113
123
|
|
|
124
|
+
@staticmethod
|
|
125
|
+
def _client_ip() -> str | None:
|
|
126
|
+
return rate_limiter.client_ip(request) if has_request_context() else None
|
|
127
|
+
|
|
128
|
+
def _login_rate_limited(self, company_short_name: str, email: str) -> dict | None:
|
|
129
|
+
"""A failure response when this account or this IP tried too often (BL-030).
|
|
130
|
+
The same answer whether or not the account exists."""
|
|
131
|
+
ip_over = rate_limiter.over_limit('login_ip', self._client_ip(), rate_limiter.LOGIN_ATTEMPTS_PER_IP)
|
|
132
|
+
if not ip_over and not rate_limiter.is_blocked('login_account', email,
|
|
133
|
+
rate_limiter.LOGIN_FAILURES_PER_ACCOUNT):
|
|
134
|
+
return None
|
|
135
|
+
self.log_access(
|
|
136
|
+
company_short_name=company_short_name,
|
|
137
|
+
user_identifier=email,
|
|
138
|
+
auth_type='local',
|
|
139
|
+
outcome='failure',
|
|
140
|
+
reason_code='RATE_LIMITED',
|
|
141
|
+
)
|
|
142
|
+
return {'success': False, 'message': self.i18n_service.t('errors.auth.too_many_attempts'),
|
|
143
|
+
'reason_code': 'RATE_LIMITED'}
|
|
144
|
+
|
|
114
145
|
def _refuse_redeem(self, company_short_name: str, reason_code: str, user_identifier: str = None) -> dict:
|
|
115
146
|
self.log_access(
|
|
116
147
|
company_short_name=company_short_name,
|
|
@@ -209,8 +240,13 @@ class AuthService:
|
|
|
209
240
|
|
|
210
241
|
def login_global_local_user(self, email: str, password: str) -> dict:
|
|
211
242
|
# company-less login: authenticates the person, the company is chosen later
|
|
243
|
+
limited = self._login_rate_limited(self.GLOBAL_ACCESS_SCOPE, email)
|
|
244
|
+
if limited:
|
|
245
|
+
return limited
|
|
246
|
+
|
|
212
247
|
auth_response = self.profile_service.authenticate_local_credentials(email=email, password=password)
|
|
213
248
|
if not auth_response.get('success'):
|
|
249
|
+
rate_limiter.record_failure('login_account', email, rate_limiter.LOGIN_FAILURES_PER_ACCOUNT)
|
|
214
250
|
self.log_access(
|
|
215
251
|
company_short_name=self.GLOBAL_ACCESS_SCOPE,
|
|
216
252
|
user_identifier=email,
|
|
@@ -220,6 +256,7 @@ class AuthService:
|
|
|
220
256
|
)
|
|
221
257
|
return auth_response
|
|
222
258
|
|
|
259
|
+
rate_limiter.clear('login_account', email)
|
|
223
260
|
self.profile_service.set_global_identity(auth_response['user_identifier'], 'local')
|
|
224
261
|
self.log_access(
|
|
225
262
|
company_short_name=self.GLOBAL_ACCESS_SCOPE,
|
|
@@ -323,9 +360,17 @@ class AuthService:
|
|
|
323
360
|
"error_message": self.i18n_service.t('errors.auth.authentication_required'),
|
|
324
361
|
"status_code": 401}
|
|
325
362
|
|
|
363
|
+
# An IP that keeps sending invalid keys is guessing them (BL-030).
|
|
364
|
+
client_ip = self._client_ip()
|
|
365
|
+
if rate_limiter.is_blocked('api_key_ip', client_ip, rate_limiter.INVALID_API_KEYS_PER_IP):
|
|
366
|
+
return {"success": False,
|
|
367
|
+
"error_message": self.i18n_service.t('errors.auth.too_many_attempts'),
|
|
368
|
+
"status_code": 429}
|
|
369
|
+
|
|
326
370
|
# check if the api-key is valid and active
|
|
327
371
|
api_key_entry = self.api_key_service.get_active_api_key_entry(api_key)
|
|
328
372
|
if not api_key_entry:
|
|
373
|
+
rate_limiter.record_failure('api_key_ip', client_ip, rate_limiter.INVALID_API_KEYS_PER_IP)
|
|
329
374
|
# Never the key itself: a mistyped or just-rotated key would end up in the logs.
|
|
330
375
|
logging.error("Invalid or inactive IAToolkit API Key: %s", self.key_fingerprint(api_key))
|
|
331
376
|
return {"success": False,
|