Securing Moodle web services and tokens

Moodle web services feed the mobile app and your integrations, so each enabled protocol, function and token is part of your attack surface. This page covers how to restrict them to what you need and verify the result.

On this page

Why Moodle web services and tokens need their own hardening pass

A Moodle site with a mobile app and several integrations almost always has more web service exposure than the team knows about. Moodle core web services support two protocols, REST and SOAP, and Moodle uses its web services internally for AJAX calls and for the official Moodle mobile app. That means the set of enabled services and functions is not only the list of integrations someone deliberately built. Each service that is switched on, each protocol that accepts requests, and each token issued against them becomes part of the attack surface, whether or not anyone remembers enabling it. The review has to start from what is actually active on the site, not from the integration documentation.

A review is worth scheduling at four points: when a new integration is added, when the mobile app is rolled out or reconfigured, when the site is upgraded to a new Moodle release, and when the security overview report flags a finding that touches web services or tokens. Each of these events can change which functions a token can reach or create a new account or service that nobody has scoped. Treat the upgrade case with care, because a new release can add or change services, so the enabled set should be checked again after the upgrade rather than assumed to carry over. Your team should confirm the exact services and functions exposed by your version against the developer documentation for External services before deciding what to keep.

The practical output of this pass is an inventory: every enabled protocol, every external service, every token and the account it belongs to, and the owner who can justify each one. Ask whoever runs your Moodle site to export or list these before any change is made, so you can compare the current state with what each integration actually needs. Any service that cannot be tied to a named integration or to the mobile app is a candidate for disabling. The rest of this topic covers how to make those decisions and how to lock them down.

Token request and web service call flow

The flow starts with a client app or integration sending credentials to login/token.php, which checks the requested service and returns a token. The client then calls the web services layer with that token, and Moodle checks the protocol, the enabled service, the requested function, and the user's capabilities before any data is returned. Review each hand-off at the trust boundary, where internet traffic reaches the Moodle server. Confirm that the token belongs to a dedicated service account with only the functions it needs.

Token request and web service call path, with checks at each Moodle hand-off.

Which web service settings to enable and when each fits

This table compares the main web service decisions for Moodle: protocol, named service, function list, token lifetime and the account behind each token. Read each row as a question to answer for your own integrations, then check the trade-off column before you enable anything.

DecisionWhen it fitsTrade-off to accept
REST or SOAP protocolREST fits most current integrations and the official mobile app path; enable SOAP only if an existing client requires itEach enabled protocol is another entry point to review, test and monitor
Official mobile app serviceUse when staff or students sign in through the Moodle mobile app and need its standard functionsThe service must include functions the app calls, so its function list is broader than a single integration needs
Custom integration serviceUse for a named external system that needs a small, fixed set of functions such as reading enrolmentsYou must build, document and maintain the function list and revisit it after each upgrade
Restricting functions per serviceLimit each service to the functions its consumer calls, checked against the function documentation for your Moodle versionNarrow lists need testing, and a missing function can break a feature until it is added back
Token expiryShorter lifetimes limit exposure of a leaked token but suit short batch jobs or interactive sessions bestFrequent expiry means more reissue steps for long-running integrations, so plan rotation as part of the build
Token scope and restricted usersScope tokens to one service and, where the platform allows it, to a restricted user for each consumerRestricted users need careful role design, and a poor design may block functions the integration needs
Dedicated service accountUse for system-to-system integrations so the integration survives staff changes and its actions are attributableThe account needs its own password or authentication controls, and someone must own its lifecycle
Personal user accountAcceptable only for short-lived, individually owned testing where the owner is accountableAccess breaks when the person leaves or changes role, and audit trails blur with personal activity

How to scope access for the mobile app versus each integration

The official Moodle mobile app authenticates users and calls web service functions on their behalf, so its token acts as the user. Moodle uses its web services for the mobile app, which means the app needs a defined set of functions for sign-in, course listing, content viewing and notifications. Scope the mobile service to those functions only, and do not add write functions to it unless a supported feature requires them.

  • Use a dedicated mobile service: Keep the app on its own external service so its function list can be reviewed separately from integrations.
  • Confirm the function list against the app version: Mobile features change between releases, so compare the functions the app calls with the list in the service before each app update.
  • Set token lifetime deliberately: Review how long mobile tokens remain valid and whether users can revoke them after a lost device.
  • Limit the protocol: Enable only the protocol the app uses, and disable SOAP and REST for the mobile service if the app does not require them.
  • Require real user accounts: Mobile tokens belong to individual users, so apply the same authentication and role rules those users hold in the browser.

Check that the mobile service contains no administrative functions and that a sample of mobile tokens maps to ordinary user accounts.

Setup sequence for locking down web services and tokens

This sequence removes unused web service paths, gives each integration its own narrow service and account, and leaves a documented record of which tokens exist and how they are checked. Each step ends with a check so the team knows the control works before moving on.

  1. Inventory enabled protocols and services

    Start by recording what is already switched on. In Site administration, review the web services overview, the enable web services setting, and which protocols (REST, SOAP and any others shown in your version) are active. List every external service defined under the web services section, who created it, and which functions it exposes. Include services used by the official Moodle mobile app and by AJAX, since those depend on core web services and must not be broken by later changes. Done when you have a written list of every active protocol, service and token holder, and an owner for each entry. Confirm the exact menu names in your Moodle version's documentation.

  2. Disable protocols and services you do not need

    Turn off protocols that no integration uses, and disable or delete external services that have no current consumer. Confirm first with each owner that an integration is retired, and check the mobile app and AJAX dependencies from the inventory before removing anything. Record each change with its reason and date in your change log. Done when the protocol list matches the inventory of real consumers and a test login to the site and the mobile app still works. Keep a rollback note for each change.

  3. Build a minimal service for each consumer

    Create one external service per integration rather than reusing a broad service for several consumers. Add only the functions that consumer calls. Use the function list from the integration's documentation or code, then remove any functions added by default that the consumer does not need. Give each service a name that identifies the consumer and its purpose. Done when each service's function list can be traced to a named integration and no service is shared by unrelated consumers.

  4. Create a dedicated service account with least privilege

    Create a separate user account for each service, not a personal account or a site administrator. Assign it only the capabilities the service functions need, usually through a custom role at system or course level. Confirm that the account is not a member of administrator roles and that it cannot sign in interactively if the integration does not need a browser session. Check it with the security report and role review, then test that the service works while the account lacks any extra permission. Done when a test call succeeds with the account and a call to a function outside its role is refused.

  5. Issue tokens with restricted scope and set expiry

    Generate a token for each service and account pair, and link it to the single service it serves. Set an expiry date where your Moodle version and the integration allow it, and record who holds each token and where it is stored. Restrict the IP address allowlist if your environment supports it, and confirm that the consuming system keeps the token in a secrets store rather than in plain configuration. Done when each token maps to one service and one account, every token has an owner and an expiry or review date, and the token list in the admin screens matches your record.

  6. Verify login/token.php behavior and check logs

    Test the token endpoint directly. Request a token with the correct credentials, then with a wrong password, a disabled account, and a suspended service, and confirm each case returns the expected response. Check that only the intended service is reachable with each token, and that a call using a token for one service fails for functions in another. Then review the web service logs and standard event logs to confirm that requests appear with the expected user and service. Done when every negative test is refused, every positive test succeeds, and the logs record the test traffic with the correct identity.

  7. Document the configuration and set a review routine

    Write down the final state: active protocols, each service with its functions, each service account and its role, each token with owner and expiry, and the test results from the previous step. Store the record with your configuration management and change log. Set a recurring review that re-runs the inventory, checks token expiry and removes unused services, and repeat it after each Moodle upgrade and plugin installation. Done when the document matches the live configuration, a second person can follow it, and the review date is assigned to a named owner.

Risks to control in Moodle web services and tokens

Moodle web services feed the official mobile app, AJAX calls and any integration you connect, so each enabled protocol, function and token widens what an attacker can reach. The cards below cover the risks that most often turn a convenient integration into an exposed path, with a check you can run against your own site.

Over-broad service function lists

A custom service often gets every function an integration might need, plus a few it never calls. Each extra function is a capability a stolen token can use. Review the functions attached to each service and remove any the integration does not call. Confirm that the mobile app service and your integration services are separate, and compare each function list against the integration's documented call list. Re-check after each plugin install, because new plugins can add functions to existing services.

External services docs

Long-lived tokens

Web service tokens that never expire keep working after a laptop is lost, a developer leaves or an integration is retired. Set an expiry or a regular rotation for each token, and tie each token to one service. Ask your Moodle administrator to list tokens with their creation dates and last use, and confirm that unused tokens are removed. Treat any token older than your rotation policy as a finding.

Shared or administrator service accounts

When an integration runs as a site administrator, a leaked token gives control over the whole site. A dedicated service account with only the roles and capabilities the integration needs limits the damage. Check which user owns each token, and confirm that no integration account holds site administrator rights or broad system-level roles. Use one account per integration so that revoking one does not break the others.

Token leakage through logs or client storage

Tokens placed in URLs end up in web server access logs, proxy logs and browser history. Tokens stored in plain client storage can be read by any script that runs in the same origin. Check that your integration sends tokens in request headers or POST bodies, that your web server and reverse proxy do not log query strings containing tokens, and that log access is restricted to the staff who need it. Ask the mobile app and integration vendors how their clients store tokens on devices.

Exposed login/token.php on public sites

The token endpoint accepts a username and password and returns a web service token, so it becomes a password guessing target on any public site. If the site does not use the mobile app or a token-based integration, restrict or block the endpoint at the web server or reverse proxy. Where it is needed, limit access to known source networks, rely on your identity provider where possible, and check that failed logins are monitored. Confirm the behavior against your own site, since routing differs between installs.

Unreviewed changes after installs or upgrades

Plugin installs and version upgrades can enable new web services, add functions to existing services or change protocol settings without anyone reviewing them. Make a web service review part of every change record. After each install or upgrade, compare enabled protocols, service function lists and token holders with the last approved baseline, and record any differences. Keep the baseline in your configuration management system so the comparison is repeatable.

How to verify the web service configuration after changes

The most useful check after any change to Moodle web services is a call made with a restricted token, because it shows whether the configuration denies what it should. Create a test user with the service account's role, issue a token for the external service you intend to allow, and call only the functions on that service. Then attempt a function outside the service, a function the role lacks capability for, and a request using a token for a service that has been disabled. Each of these should fail. Record the exact function names, the error returned and the date, so the same tests can be repeated later. Confirm with your team's security owner which test accounts may be used, where they are created and how they are removed afterwards, since test tokens are themselves credentials.

Next, review the Moodle security overview report and the site logs. The report flags settings that weaken the site, and it should be read alongside the web service pages in administration, which list enabled protocols, external services and the functions each one exposes. Check the logs for token creation, failed token requests against login/token.php, and web service calls from unexpected users or addresses. Ask your team what the expected baseline looks like before you start, because a finding is only useful if someone can say whether it is new. Keep the report output with the change record so auditors and your own reviewers can see what was checked.

Re-run these tests after each Moodle upgrade and after every plugin install, because either can add functions, change default roles or alter how a protocol behaves. Moodle 5.1 requires a move of the web server document root to public, and each major release carries its own changes, so the plan for 5.2 or 5.3 should name the re-test as a step, not an afterthought. Confirm the release notes for your target version and the Moodle security release notices with the team that owns the site, and agree a written test script that covers both the denials and the functions the mobile app and integrations still need. Note that the test methods, accounts and pass criteria should be agreed with your security owner before the first run.

Limits and what to confirm in your environment

The controls on this page depend on details that differ by Moodle version, mobile app release and local plugins. The cards below list what to verify with the vendor or in your own testing before you change production settings, so the lockdown matches what your services actually call.

Confirm which functions your apps call

Before you restrict a service, list the web service functions your mobile app version, AJAX calls and each integration actually invoke. Capture this from logs or a staging test run, not from memory or documentation alone. Remove a function only after a test pass of every workflow that uses it, because a missing function often fails silently for one user group, such as students submitting assignments from a phone. Record the mapping so future upgrades can be checked against it.

External services docs

Confirm token expiry options

Token lifetime controls differ between Moodle versions and between the core settings and any plugin that issues tokens. Check in your target version which expiry, validity and per-user token options exist in the administration pages, and whether a token can be revoked without deleting the user. Test an expired token against the mobile app and a custom integration so you know what users see and how the integration recovers.

Confirm how plugins add services

Third-party plugins can register their own external services and functions, which then appear alongside core services. Inventory every service on the site after each plugin install, and confirm which functions each plugin exposes, what capabilities they check and whether they are enabled by default. A plugin service that is not in your design is an unreviewed entry point, so the inventory should be part of your plugin vetting routine.

Moodle plugin types

Confirm web server logging retention

Token misuse is often visible only in web server access logs and Moodle's own logs, and each has its own retention setting. Confirm how long your reverse proxy, web server and Moodle log store keep requests to the webservice and token endpoints, who can read them and whether they reach your central log platform. If retention is shorter than your incident response window, token abuse may not be traceable after the fact.

Confirm whether SOAP is needed

Moodle core provides both REST and SOAP web service protocols. Many modern integrations and the official mobile app use REST, so SOAP may be enabled only because it was never turned off. Ask each integration owner whether they depend on SOAP and, if not, disable the protocol in the web service settings and retest. Keeping an unused protocol enabled adds a surface you must review, patch and monitor.

Confirm service account ownership

Integrations usually authenticate as a dedicated user rather than a person, and that user's role assignments define what every token can do. Confirm who owns each service account, which roles and capabilities it holds in your Moodle version, and whether the account can sign in interactively. Check that its password cannot be used for normal login and that a departure or role change triggers a review of its tokens.

Questions teams ask before securing Moodle web services

Can our own team lock down Moodle web services without a partner?

Yes, a team with Moodle administration and PHP experience can review and restrict web services in-house, and the work is mostly configuration, testing and documentation. The harder part is knowing which services your mobile app and integrations actually call, because a service you disable by mistake can break sign-in or sync without an obvious error. Teams that take this on usually need one person who owns the integration inventory, one who can test each integration after changes, and a staging copy of the site to try changes first. If those three roles are hard to fill, an outside partner can take the review as a fixed-scope piece of work with written deliverables.

What makes the effort for web service hardening larger or smaller?

The main drivers are the number of integrations that call Moodle, how many custom web service functions you have written or installed, whether the official Moodle mobile app is in use, and how many plugins expose their own external functions. Each integration needs its own service definition, a dedicated account, a token scope and a test case, so ten integrations take far more work than two. Custom functions need a review of what data they return and who can call them. Plugin count matters because each plugin can add functions that are enabled by default in a service you did not plan to expose. Core web service protocols are REST and SOAP, so the protocols in use also affect which endpoints you must check.

What does the client need to provide before the work starts?

Before the work starts, you need an inventory of every system that calls Moodle through web services, including the mobile app, reporting tools, HR feeds and any LTI or custom scripts. For each one, name an owner who can confirm which functions it needs, who approves changes and who will test after a change. You also need a test environment that matches production closely enough to run the integrations, plus access to the Moodle site with administrator rights and to the server logs. Ask for a list of current tokens, their creation dates and the accounts they belong to, because that list is the baseline for measuring what changes. Without these inputs, the review tends to stall while owners are found.

How long does web service hardening take?

No fixed duration applies to every site, because the time depends on the integration count, the number of custom functions and how quickly owners can confirm their needs and test. A small site with one mobile app and one integration can be reviewed quickly, while a site with many feeds and custom functions needs separate testing cycles for each. Ask any provider to split the timeline into inventory, configuration changes, testing in staging, production cutover and a short period of monitoring. Also ask how long owner confirmation is expected to take, since that step is often the longest and sits outside the implementer's control. A written timeline should name the dependencies, not just the total.

Does a Moodle upgrade change our web service and token configuration?

An upgrade can change behavior, so you should re-check web service settings after every major or minor upgrade rather than assume they carried over unchanged. Moodle ships major releases every six months and minor point releases every two months, and each release can add, rename or deprecate external functions. Review the release notes for the version you are moving to, rerun your integration tests in staging, and confirm that tokens still map to the right service accounts. Keep the service definitions in version control or export them so you can compare before and after. Moodle 5.1 and 5.3 also have their own server requirements, which can affect the test environment you use.

How should we set token expiry and service accounts?

Give each integration its own dedicated service account with only the capabilities that integration needs, and avoid sharing one administrator account across several tools. Set token lifetimes to match how often the integration runs and how often you rotate credentials, and record an owner and renewal date for each token. Enable only the services and functions each integration calls, because the scope of a token is limited by the service it belongs to. Confirm these settings on a staging site first, then document them in the change record. The exact settings and their names depend on your Moodle version, so confirm them against the release notes and the external services documentation for the version you run.

What should a quote for this work include?

A useful quote lists the written scope, including the integrations covered, the custom functions reviewed, the Moodle version and environments in scope, and whether the mobile app is included. It should name the deliverables, such as the integration inventory, the service and token configuration record, test results, a change runbook and a list of open owner decisions. Ask how the provider handles owner delays, what a retest after fixes includes, and which items are one-time and which recur, such as periodic token reviews after each upgrade. The quote should also state the client responsibilities from this page, so you can see what your team must supply and when. DeployOpen does not publish a price list, and a quote follows from the written scope.

How DeployOpen scopes and delivers web service hardening

DeployOpen starts web service hardening with a written scope, agreed before any change is made to your Moodle. The scope names the sites in question, which web service protocols are in use (REST and SOAP are the two core options), which services and functions the mobile app and each integration actually call, and which token holders are in place today. Deliverables are listed alongside it: an inventory, a list of changes to the service configuration, the token and service account changes, and the verification steps that show the result. Because the scope is fixed, your security, identity and integration teams can review it against their own requirements before work begins, and any extra work is raised as a written change rather than absorbed quietly into the original price.

The inventory is the core of the work and it happens on your own Moodle, inside your infrastructure. DeployOpen reviews the web services settings, the external services defined on the site, the enabled protocols, the tokens already issued and the service accounts that hold them, and the integrations that depend on each. Each finding is recorded with its owner and the reason the access exists, so that nothing is disabled that a mobile release or an integration still needs. Changes are then made in a staging copy first, with the mobile app and each integration tested against the reduced set. Where security testing is in scope, the same scope covers attempts to use tokens outside their intended functions and checks of the login/token.php path, with findings and retest results delivered in writing.

Some work recurs after the first delivery. Token expiry, service account ownership and the list of enabled functions change when the mobile app, Moodle core or a plugin is updated, so DeployOpen can offer a retainer that covers upgrades, repeated checks and retesting against your scope. The cost components to ask about in any quote are the inventory effort, the staging and testing effort, any security testing, and whether the retainer covers each Moodle minor release. Ask DeployOpen to state which items are one-time and which recur, and ask how a new integration would be added to the scope. DeployOpen does not issue certifications or audit reports, so any assurance your auditor needs must come from that auditor's own review of the evidence delivered.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.