Security Contract¶
Assertions¶
SEC-001 - Joplin credentials never enter public output or workspace state¶
Contract: The Joplin token MUST be accepted only from JOPLIN_TOKEN or a
token file, except that the local process mcp stdio MAY also accept the
compatibility argument --token TOKEN, whose value is visible to other local
processes and IDE configuration readers. Every Joplin and MCP token file MUST
be a bounded single-line regular file opened without following symlinks. On POSIX it MUST be owned by the current user with no group or other
access. On Windows it MUST be owned by the current user, SYSTEM, or
Administrators, and no effective allow entry of its ACL MAY give another
account read, write, or permission-change rights. Rejections MUST NOT echo the
file content. Every accepted form MUST be redacted from stdout, stderr, log
files, and logged tracebacks and MUST NOT be stored in workspace files. Stdio
stdout MUST contain only protocol messages, and stdio mode MUST NOT open HTTP
interfaces or accept their bearer credentials. Authentication failure MUST not
echo remote response content containing the credential.
Evidence:
test_token_never_in_output_on_auth_error-tests/integration/test_cli_contract.py::TokenSafetyTest::test_token_never_in_output_on_auth_errortest_token_never_in_log_file-tests/integration/test_cli_contract.py::TokenSafetyTest::test_token_never_in_log_filetest_token_not_stored_in_workspace-tests/integration/test_cli_contract.py::TokenSafetyTest::test_token_not_stored_in_workspacetest_configuration_errors_never_write_to_protocol_stdout-tests/integration/test_mcp_stdio.py::McpStdioCliTest::test_configuration_errors_never_write_to_protocol_stdouttest_lifecycle_tools_live_call_and_protocol_errors-tests/integration/test_mcp_stdio.py::McpStdioCliTest::test_lifecycle_tools_live_call_and_protocol_errorstest_stdio_has_no_http_listener_or_interface_bearer_options-tests/integration/test_mcp_stdio.py::McpStdioCliTest::test_stdio_has_no_http_listener_or_interface_bearer_optionstest_file_and_environment_tokens_are_redacted-tests/integration/test_mcp_stdio.py::McpStdioCliTest::test_file_and_environment_tokens_are_redactedtest_token_file_must_be_private_owned_and_not_a_symlink-tests/unit/test_stdio_token.py::test_token_file_must_be_private_owned_and_not_a_symlinktest_token_file_content_is_bounded_single_line_ascii-tests/unit/test_stdio_token.py::test_token_file_content_is_bounded_single_line_asciitest_insecure_token_file_is_rejected_for_workspace_commands-tests/integration/test_cli_contract.py::TokenSafetyTest::test_insecure_token_file_is_rejected_for_workspace_commandstest_internal_error_traceback_is_redacted_on_stderr_and_log_file-tests/integration/test_mcp_stdio.py::McpStdioCliTest::test_internal_error_traceback_is_redacted_on_stderr_and_log_filetest_windows_acl_accepts_private_files_owned_by_trusted_principals-tests/unit/test_auth.py::test_windows_acl_accepts_private_files_owned_by_trusted_principalstest_windows_acl_rejects_foreign_owner_and_other_account_access-tests/unit/test_auth.py::test_windows_acl_rejects_foreign_owner_and_other_account_accesstest_windows_token_file_rejects_access_for_other_accounts-tests/unit/test_auth.py::test_windows_token_file_rejects_access_for_other_accounts
SEC-002 - Remote network exposure always requires explicit authorization¶
Contract: Joplin API addresses outside loopback MUST require
--allow-remote-api. MCP listeners outside loopback MUST require both
--allow-remote-mcp and protected MCP bearer authentication. Browser-origin
requests MUST pass the configured Origin policy.
Evidence:
test_non_loopback_refused_without_flag-tests/unit/test_config.py::ResolveBaseUrlTest::test_non_loopback_refused_without_flagtest_non_loopback_bind_requires_flag_and_auth-tests/integration/test_mcp_server.py::McpCliSafetyTest::test_non_loopback_bind_requires_flag_and_authtest_http_validation_and_origin_protection-tests/integration/test_mcp_server.py::McpHttpTest::test_http_validation_and_origin_protection
SEC-003 - Bearer sources are strong, protected, and rotatable¶
Contract: MCP bearer sources MUST be token files protected as defined by
SEC-001 on POSIX and Windows, not symlinks or directories, and
contain one bounded URL-safe Base64 value encoding at least 256 bits.
Files MUST be re-read per request and comparisons MUST fail closed for
non-ASCII, malformed, oversized, or duplicate authorization.
Evidence:
test_token_format_requires_bounded_urlsafe_base64_and_256_bits-tests/unit/test_auth.py::test_token_format_requires_bounded_urlsafe_base64_and_256_bitstest_mcp_source_rejects_insecure_permissions_and_symlinks-tests/unit/test_auth.py::test_mcp_source_rejects_insecure_permissions_and_symlinkstest_windows_token_file_rejects_access_for_other_accounts-tests/unit/test_auth.py::test_windows_token_file_rejects_access_for_other_accountstest_bearer_authentication_and_rotation-tests/integration/test_mcp_server.py::McpHttpTest::test_bearer_authentication_and_rotation
SEC-004 - Filesystem inputs cannot escape or redirect traversal¶
Contract: Remote titles and local relative paths MUST be sanitized and checked against the workspace root. Workspace scanning and bearer-file loading MUST reject symlinks. Local replacements MUST be atomic, and destructive sync operations MUST retain backup or quarantine evidence.
Evidence:
test_traversal_rejected-tests/unit/test_paths.py::SafeRelPathTest::test_traversal_rejectedtest_symlink_not_followed-tests/integration/test_cli_contract.py::SecurityScanTest::test_symlink_not_followedtest_mcp_source_rejects_insecure_permissions_and_symlinks-tests/unit/test_auth.py::test_mcp_source_rejects_insecure_permissions_and_symlinkstest_remote_delete_reported_then_quarantined-tests/integration/test_push_pull.py::PullChangesTest::test_remote_delete_reported_then_quarantined
SEC-005 - Untrusted note content is data, never executable input¶
Contract: Runtime modules MUST NOT invoke a shell, subprocess, dynamic
eval, or dynamic exec. Note bodies, titles, tags, tool arguments, and tool
results MUST be treated as data and MUST not become filesystem paths or command
arguments outside their validated domain adapters.
Evidence:
test_runtime_has_no_code_execution_surface-tests/unit/test_security_policy.py::test_runtime_has_no_code_execution_surfacetest_schema_validation_precedes_side_effects-tests/integration/test_mcp_server.py::McpHttpTest::test_schema_validation_precedes_side_effects
SEC-007 - Destructive boundaries match Joplin recovery capabilities¶
Contract: Sync and direct note/notebook operations MUST use Joplin trash and support restore. Tag and resource deletion MAY be permanent because Joplin has no trash API for them and MUST be marked destructive in registry metadata. MCP MUST report the actual deletion class.
Evidence:
test_notebook_crud_nesting_notes_trash_and_restore-tests/integration/test_mcp_server.py::McpHttpTest::test_notebook_crud_nesting_notes_trash_and_restoretest_tag_crud_listing_and_note_relations-tests/integration/test_mcp_server.py::McpHttpTest::test_tag_crud_listing_and_note_relationstest_resource_crud_content_and_note_relations-tests/integration/test_mcp_server.py::McpHttpTest::test_resource_crud_content_and_note_relationstest_local_delete_propagated_to_trash-tests/integration/test_push_pull.py::PushTest::test_local_delete_propagated_to_trash
SEC-008 - GitHub OAuth permits one verified numeric account¶
Contract: OAuth configuration MUST require one positive ASCII decimal GitHub
user ID. Login hints, email, unverified JWT claims and API scopes alone MUST NOT
authorize an account. Issuance, refresh and protected requests MUST verify the
current account via GitHub /user before downstream tokens are issued or a
tool runs. An upstream grant that GitHub already rotated MUST be retained when
that verification is temporarily unavailable, so the same downstream refresh
can be retried. Only within-request positive caching is permitted. Downstream
redirect URIs MUST exactly match the hosted Claude callback
https://claude.ai/api/mcp/auth_callback; DCR, PKCE, consent/state and one-use
code/refresh binding MUST remain enforced. Unverified registrations MUST stay
pending with a bounded count and lifetime until an owner login establishes
them; registration, token and browser-flow requests MUST have separate rate
budgets. Client credentials MUST remain independent across OAuth, legacy MCP
and Joplin, comparing the signing key as key material in every accepted
encoding. Codes, credentials and note bodies MUST NOT enter application/SDK
logs. GitHub expiring access and refresh token formats MUST be validated before
issuing client credentials. The consent page MUST warn the owner not to approve
a connection they did not start, and MUST fail closed instead of rendering an
approval without that warning.
Evidence:
test_identity_uses_verified_id_and_normalized_api_scopes-tests/oauth/unit/test_identity.py::test_identity_uses_verified_id_and_normalized_api_scopestest_foreign_github_account_cannot_issue_access_or_mutate-tests/oauth/e2e/test_oauth_flow.py::test_foreign_github_account_cannot_issue_access_or_mutatetest_invalid_pkce_state_code_replay_and_redirect-tests/oauth/e2e/test_oauth_flow.py::test_invalid_pkce_state_code_replay_and_redirecttest_concurrent_code_and_refresh_are_single_use-tests/oauth/integration/test_provider_flow.py::test_concurrent_code_and_refresh_are_single_usetest_signed_wrong_audience_issuer_type_and_expired_tokens_are_rejected-tests/oauth/integration/test_provider_flow.py::test_signed_wrong_audience_issuer_type_and_expired_tokens_are_rejectedtest_explicit_refresh_survives_identity_outage_after_rotation-tests/oauth/e2e/test_oauth_recovery.py::test_explicit_refresh_survives_identity_outage_after_rotationtest_transparent_refresh_survives_identity_outage_without_running_tools-tests/oauth/e2e/test_oauth_recovery.py::test_transparent_refresh_survives_identity_outage_without_running_toolstest_owner_login_establishes_client_and_foreign_or_abandoned_stay_pending-tests/oauth/integration/test_provider_flow.py::test_owner_login_establishes_client_and_foreign_or_abandoned_stay_pendingtest_pending_registrations_expire_without_reset-tests/oauth/integration/test_provider_flow.py::test_pending_registrations_expire_without_resettest_dcr_registration_capacity_preserves_existing_owner_grant-tests/oauth/e2e/test_oauth_lifecycle.py::test_dcr_registration_capacity_preserves_existing_owner_granttest_signing_key_reuse_is_rejected_in_any_accepted_encoding-tests/oauth/unit/test_config.py::test_signing_key_reuse_is_rejected_in_any_accepted_encodingtest_consent_page_warns_once_and_keeps_its_security_headers-tests/oauth/integration/test_provider_flow.py::test_consent_page_warns_once_and_keeps_its_security_headerstest_consent_page_without_its_heading_fails_closed-tests/oauth/integration/test_provider_flow.py::test_consent_page_without_its_heading_fails_closed
SEC-009 - OAuth state is private, encrypted and exclusively managed¶
Contract: Persistent OAuth credentials MUST be encrypted in a private, dedicated directory outside sync state with an exclusive process lock and validated schema. Incompatible/corrupt state or a wrong signing key MUST fail closed without resetting existing grants. Reset MUST require explicit local confirmation and the same exclusive lock. Restart MUST retain valid grants; changing the allowed account or resetting state MUST deny old access. Quota or storage failures MUST NOT evict existing valid grants to admit new ones.
Evidence:
test_encrypted_state_restart_exclusive_lock_and_reset-tests/oauth/unit/test_config.py::test_encrypted_state_restart_exclusive_lock_and_resettest_corruption_and_wrong_key_preserve_state-tests/oauth/unit/test_config.py::test_corruption_and_wrong_key_preserve_statetest_state_quota_invalid_ttl_and_disk_failure_preserve_existing_grants-tests/oauth/unit/test_config.py::test_state_quota_invalid_ttl_and_disk_failure_preserve_existing_grantstest_changed_owner_and_explicit_local_reset_deny_old_grants-tests/oauth/e2e/test_oauth_flow.py::test_changed_owner_and_explicit_local_reset_deny_old_grants
SEC-010 - OAuth security events are recorded without credentials¶
Contract: The OAuth service MUST record registrations, consent decisions
and forgery attempts, callback binding failures, foreign GitHub accounts,
token issuance, refresh success and replay, rejected resource tokens, rate
limiting, GitHub outages and local resets as single-line audit events. Events
MUST contain only a fixed name and whitelisted, validated fields, and MUST NOT
contain tokens, codes, state, transaction or CSRF values, secrets, request
content, client metadata or forwarded addresses. Anonymous-triggerable events
MUST be throttled per event and reason with a suppressed count. Audit events
MUST be visible at default service verbosity.
Evidence:
test_security_events_are_recorded_without_credentials-tests/oauth/e2e/test_oauth_security.py::test_security_events_are_recorded_without_credentialstest_foreign_github_account_cannot_issue_access_or_mutate-tests/oauth/e2e/test_oauth_flow.py::test_foreign_github_account_cannot_issue_access_or_mutatetest_only_whitelisted_and_valid_values_are_written-tests/oauth/unit/test_audit.py::test_only_whitelisted_and_valid_values_are_writtentest_anonymous_events_are_throttled_with_suppressed_counts-tests/oauth/unit/test_audit.py::test_anonymous_events_are_throttled_with_suppressed_countstest_cli_logging_shows_security_events_without_verbose-tests/oauth/unit/test_audit.py::test_cli_logging_shows_security_events_without_verbose