Repository navigation
Security Model
Moodle CLI handles authentication material, talks to a university service, and can submit work. Its security boundary is intentionally narrow and visible.
- Tokens and browser sessions are stored in the operating-system keychain under Moodle CLI's own entries. The configuration file contains metadata only.
- A machine with no keychain — headless Linux, SSH, WSL, a container — can keep them in a file
instead, with
--credential-store fileorpreferences.credential_store: file. Nothing switches to a file on its own: the file iscredentials.jsonbeside the configuration, created0600in a0700directory, andauth loginreports the path. Mode0600keeps other accounts on the machine out and nothing else — it does not protect against anything running as this user, which is equally true of an unlocked desktop keychain. Windows has no mode bits, so there the file relies on the ACL%APPDATA%already carries; Credential Manager is the default on that platform anyway. -
MOODLE_WS_TOKENandMOODLE_SESSIONsupply an ephemeral credential for one process and take precedence over stored credentials. - Secrets should enter through stdin or environment variables, not command-line arguments.
-
auth logoutdeletes the local copy. It does not revoke the Moodle token because that token may be shared with the official mobile app.
Browser profile access happens only after auth import-browser. The command searches Safari on
macOS, Firefox, or Chromium-family storage for the requested host. Other cookies may be parsed
because browsers store them together, but only the matching Moodle session is returned or stored;
none are logged. An explicit --browser safari does not inspect other browser profiles.
Not finding a cookie means only that it was absent from the readable browser snapshot. It does not prove the user is signed out.
auth import-session does not read any browser profile. It accepts one cookie at a hidden terminal
prompt, or from an explicitly requested stdin pipe, verifies it with the chosen Moodle site, then
stores it in the OS keychain. The value is not accepted as a command-line argument or echoed in
diagnostics. The person running the command must copy the cookie from their own browser; it must
never be sent in a screenshot, chat, or issue.
The automatic mobile-launch callback uses per-user desktop and D-Bus service files. D-Bus activation
keeps the token-bearing callback out of /proc/<pid>/cmdline. A callback is accepted only when it:
- matches a live, unexpired login transaction;
- carries the expected site hash and passport proof;
- has not already been claimed; and
- contains a token the target Moodle site accepts.
On macOS, a per-user application receives the URL as an Apple Event and sends it to the CLI through an anonymous stdin pipe. It never writes the token to a temporary file or a process argument. The CLI forwards it through the same private Unix socket and transaction checks as Linux. The locally compiled application is signed ad hoc; the release binary retains its separate release signing. Windows automatic callbacks remain unsupported.
- Requests go only to the configured Moodle origin. Credentials are not forwarded cross-origin.
-
moodle api callclassifies functions with a manually reviewed mutation/retry registry. A function that is not on it is classified as a write and never retried. -
moodle ws call,ws_readandws_writeuse the effect in the generated registry instead. It comes from the type Moodle declares for the function, a rule that makes credential-issuing functions writes, and an explicit list of functions that Moodle declares read but that log a view or run plugin code:tool_mobile_get_content, the sevencore_competency_*_viewedfunctions,core_blog_view_entriesandmod_lti_view_lti.--read-onlyand a read-only MCP session, including a remote client ofmcp host, refuse them. -
core_get_fragmentis declared read and dispatches to any component'soutput_fragment_*callback, so whether a call writes depends on the callback. The registry deliberately leaves it a read; treating it as a write is a decision for the maintainer. - AJAX and HTML adapters are read-only.
- Assignment writes are reconciled by reading the resulting state. If the state remains unknown, the
outcome is
ambiguousand automatic retry is forbidden. - Request throttling and Moodle's
Retry-Afterare respected.
moodle mcp host is the one command that accepts network connections. It listens on the address
given by --listen, which should be loopback, and is meant to sit behind a tunnel or proxy that
terminates HTTPS. Without --public-url it starts a Cloudflare quick tunnel itself, which publishes it
at a random address until it stops. It binds the port first and points the tunnel at that listener,
runs cloudflared with a configuration file of its own and without MOODLE_* and TUNNEL_*
environment variables, runs it under a guard process that stops it if the host is killed, and checks that the public address
reaches it before announcing it. A client reaches the tools only with an access token issued after the owner enters
the host passphrase on a page that names the site, the access being granted, and where the browser
returns. Sign-ins are held in memory and end when the process stops. While it runs, the host holds
the account's Moodle credential, and anyone it has admitted acts as that account. The tunnel provider
and Anthropic can see the traffic, and course content written by other people reaches Claude, which
matters most when writing is on. The log records each tool call's name, outcome, and duration, never
its arguments. Claude connector lists every control and limit.
At an interactive terminal, a command that succeeds may print one notice on stderr when a newer
release exists. To know that, the program sends github.com a HEAD request for
https://github.com/KoukeNeko/Moodle-CLI/releases/latest and reads where it redirects, at most once
a day. The answer is kept in update-check.json in the user cache directory. The request carries no
account, site, or credential, only the user agent moodle-cli/<version>; GitHub sees that and the
address it came from, as it would for a download. Only a vX.Y.Z tag on this repository's own page is
accepted, and the address in the notice is built from that tag rather than copied from the response.
Nothing is downloaded, installed, or run because of it.
No request is made with --json or --no-input, for mcp, completion and help, when stderr is not a
terminal, when CI is set, in a build that is not a release, or when MOODLE_CLI_NO_UPDATE_CHECK is
set to anything but 0, false, no, or off. A network that never answers delays a command by at
most one second, once a day.
The CLI cannot protect a compromised operating system, an unlocked user keychain, a malicious Moodle server, or a browser profile readable by another local process. It provides no telemetry, self-update, privilege escalation, process injection, or remote credential backup.
Report a suspected vulnerability privately to the repository owner before opening a public issue when disclosure would expose users or credentials.
Moodle CLI
- Home · 繁中
- Installation · 安裝
- Authentication and sites · 登入與站台
- Commands · 命令
- Complete command reference · 完整命令參考
- Feature coverage · 功能覆蓋
- Roles and capabilities · 角色與 capability
- Scale test model · 規模測試模型
- Report contract · 報告契約
- JSON contract · JSON 契約
- Automation recipes · 自動化範例
- Claude connector · Claude connector
- Security model · 安全模型
- Development and testing · 開發與測試