Notes · Oleksandr Osadchyi · Updated · 12 min read

Magento admin API token security: the login path your /admin rule does not cover

Many Magento 2 and Adobe Commerce stores put Cloudflare Access, HTTP basic auth or an IP allowlist on the /admin path and consider the admin closed. That rule covers the admin login page. It does not cover POST /rest/<store>/V1/integration/admin/token, the documented REST endpoint where an admin username and password are exchanged for a bearer token. This endpoint is under /rest on every install, and it stays there when you change the Admin URL. The fix has two parts: keep native two-factor authentication on and verify that it is really enforced, and extend the same edge rule to the admin token path and the 2FA provider endpoints under /rest.

I am Oleksandr Osadchyi, an ex-Magento 2 core engineer and Adobe Certified Master, Adobe Commerce Architect, with more than 10 years on Magento stores.

What a rule on /admin protects

A rule on the admin path is a good control, and I recommend it. It covers the HTML admin: the login form, the dashboard, every page under the admin frontName. The problem is scope. Edge rules are scoped by path. In Cloudflare Access, application paths define the URLs protected by an Access policy. You protect either the whole hostname, by leaving the path empty, or a specific subdomain and path. A path covers itself and what is under it. A wildcard path like example.com/alpha/* covers the subpaths of /alpha and does not cover /alpha itself or the apex. When several rules share a root path, the more specific rule wins and deeper paths inherit the parent rule.

/rest is not under /admin. So an Access application for store.example.com/admin covers the admin HTML pages and nothing else. An nginx basic auth location on /admin and an IP allowlist on /admin behave the same way. The store owner sees a login prompt in front of the admin and assumes the admin is closed. The authentication API is still open to the internet.

The admin token endpoint is on every store

The route is declared in the core Magento_Integration module, in its webapi.xml: <route url="/V1/integration/admin/token" method="POST">, mapped to Magento\Integration\Api\AdminTokenServiceInterface::createAdminAccessToken, with <resource ref="anonymous"/>. Anonymous is normal here. It is a login endpoint, so the caller has no token yet. It is present on Magento Open Source, on-premise Adobe Commerce and Adobe Commerce on cloud infrastructure.

This is the normal, documented API call that every integration uses to obtain an admin token. It is described in Adobe's token-based authentication guide:

POST https://<host>/rest/<store_view_code>/V1/integration/admin/token

{"username": "...", "password": "..."}

The response body is the token as a plain string. The client then sends it as Authorization: Bearer <token> on every further request. Inside the application the service method createAdminAccessToken($username, $password) calls $this->userModel->login($username, $password) and issues the token on success. The same service contract is also exposed over SOAP. GraphQL has no mutation that creates an admin token, so REST is the path to think about.

Now the part people miss. All application traffic, the storefront, /rest and /graphql, goes through one front controller, pub/index.php. The nginx.conf.sample in the Magento repository has root $MAGE_ROOT/pub;, a catch-all location / { try_files $uri $uri/ /index.php$is_args$args; } and one PHP entry block. There is no location block for ^/rest, for ^/graphql or for the admin frontName. These prefixes are resolved by the application. The /rest prefix is fixed inside the Web API front controller. The Admin URL setting renames only the adminhtml area route. Changing it from /admin to /secret-backend-2026 moves the HTML admin and leaves /rest/.../V1/integration/admin/token exactly where it was.

One exception: on Adobe Commerce as a Cloud Service, the SaaS product, the traditional admin and integration tokens are not supported. An IMS token obtained through OAuth is used instead, and the API host is different. This article is about Magento Open Source, on-premise Adobe Commerce and Adobe Commerce on cloud infrastructure.

What really gates the token endpoint

The controls that act on this endpoint live inside the application. The table shows which native control protects what. The sections after it give the details and the config paths.

ControlConfig path or placeWhat it protects
Custom Admin URLAdmin frontNameThe adminhtml HTML routes only. /rest does not move.
Cloudflare Access, basic auth or IP allowlist on /adminEdge or web server/admin and its subpaths only.
Admin CAPTCHA and reCAPTCHAAdvanced > Admin > CAPTCHAAdmin Login and Admin Forgot Password HTML forms only.
Admin account lockoutadmin/security/lockout_failures = 6, admin/security/lockout_threshold = 30 minAdmin UI login only. The observer is registered in the adminhtml area.
OAuth request throttleoauth/authentication_lock/max_failures_count = 6, oauth/authentication_lock/timeout = 1800 sThe token endpoint, counted per username, not per IP.
Native 2FAMagento_TwoFactorAuth, mandatory since 2.4.0Admin UI and Web API token. Off in Adobe IMS mode or with a bypass module.
Admin token lifetimeoauth/access_token_lifetime/admin = 4 hoursHow long an issued admin token stays valid.

Native two-factor authentication is the main control

The Magento_TwoFactorAuth module ships in the magento/security-package repository and is bundled with the core since 2.4.0. Two-factor authentication became mandatory for the Admin in 2.4.0, released on 28 July 2020. The 2.4.0 release notes say:

Admin users must first configure their 2FA before logging into the Admin through either the UI or a web API.

The scope includes the Web API, and that is the important part.

With native 2FA enforced, the generic endpoint above does not return a token for a username and password. It returns an error that tells the caller to use the 2FA provider-specific endpoints. The token has to be requested from a provider endpoint that also takes the second factor, for example POST /rest/<store_code>/V1/tfa/provider/google/authenticate with the fields username, password and otp. The other providers have their own routes:

Adobe's own REST tutorial states it in one line:

To get a token, you must have 2FA configured.

So on a store with native 2FA enforced, a valid admin password alone does not produce an admin token.

Three things reopen this gap, and you should check all three.

First, Adobe IMS authentication. Adobe's 2FA documentation says that stores with Adobe Identity Management Services authentication enabled have native 2FA disabled. If your admins log in through IMS, the native module is no longer in front of the token endpoint.

Second, third-party modules that turn 2FA off for API token generation. Several public packages add an environment variable or a config option to let the generic token endpoint work on username and password again. The native module has no such option. Its config.xml has:

A key like enable_for_api_token_generation comes from a third-party module. These modules are common on development and staging servers, and they sometimes reach production with the same codebase.

Third, 2FA is an application-layer control. It acts after the request has reached pub/index.php. It decides what the response is. It does not make the endpoint unreachable.

Two different lockouts, and the one you know is not the one that runs

The lockout you see in the admin, under Advanced > Admin > Security, is admin/security/lockout_failures with a default of 6 and admin/security/lockout_threshold with a default of 30 minutes. It is implemented by Magento\User\Observer\Backend\AuthObserver. That observer is registered only in the module's etc/adminhtml/events.xml, so it runs in the adminhtml area. The token endpoint runs in the webapi_rest area. The user model still dispatches the admin_user_authenticate_before and admin_user_authenticate_after events during the token request, but nothing in the REST area listens for the lockout. This setting protects the admin login form and nothing else.

The token endpoint has its own throttle. AdminTokenService::createAdminAccessToken calls the OAuth RequestThrottler before and after the login attempt. Its config is oauth/authentication_lock/max_failures_count = 6 and oauth/authentication_lock/timeout = 1800 seconds, which is 30 minutes. When the count is reached the service throws an authentication exception and the account is locked for the API until the timeout passes. On success the counter resets.

The throttler counts by username and user type. It does not count by source IP. For defense this means one thing: the lock slows repeated attempts against one known account. It does not limit a single source across many accounts, and it does not limit many sources against the same path. An IP rate limit is a different control, and the application does not have one for this route. That job belongs to the edge or the web server, and today most stores have not given it to them.

CAPTCHA and reCAPTCHA

Admin CAPTCHA is configured under Stores > Settings > Configuration > Advanced > Admin > CAPTCHA. The forms you can select are Admin Login and Admin Forgot Password. The CAPTCHA observers are registered in the adminhtml area and bound to backend form actions. The REST token route neither renders nor validates a CAPTCHA. Adobe reCAPTCHA for the Admin is also a form-level control on the login and forgot-password forms. Both are worth having, and neither touches the API.

Token lifetime

An admin token is valid for oauth/access_token_lifetime/admin hours, 4 by default. A customer token lives 1 hour by default. Integration tokens have no expiry and are valid until revoked. The setting is under Stores > Settings > Configuration > Services > OAuth > Access Token Expiration, and an hourly cron removes expired tokens.

What Adobe's hardening guides say, and what they leave out

Adobe's Configure Admin security page recommends:

It does not mention the Web API or the token endpoint. Its only IP references are the password-reset options.

The Secure your Commerce site and infrastructure page in the Implementation Playbook adds:

Its brute-force advice is:

Enable reCAPTCHA to protect the Admin from automated brute force attacks.

As shown above, reCAPTCHA covers the HTML form. The page does not say to restrict the REST admin token path at the web server, CDN or WAF.

Adobe's own Fastly allowlist example for cloud stores shows the pattern clearly. The snippet restricts the admin path to an IP list:

if ((req.url ~ "^/admin") && !(client.ip ~ allowlist) && !req.http.Fastly-FF) { error 403 "Forbidden"; }

The note under it says:

If the URL for your Admin was changed, replace the sample value /admin with the URL for your environment.

It requires the Fastly CDN module for Magento 2 v1.2.58 or later. The match is ^/admin. By Adobe's own example, the request to /rest/.../V1/integration/admin/token does not match and passes through. Nothing in the three documents tells you to add the token path. A careful operator adds it anyway.

Hardening checklist

1. Verify that native 2FA really gates the API

Open the 2FA configuration and confirm the module is enabled. Check whether Adobe IMS authentication is on for your admins; if it is, native 2FA is off and the token endpoint accepts username and password. On staging, with a test admin account, send the documented token request to the generic endpoint and confirm you get the error that points to the 2FA provider endpoints, and no token. Do this after every deployment that touches authentication.

2. Audit the codebase for 2FA bypass modules

Ask your developer to list every module that disables 2FA or adds API token generation without 2FA, in composer.lock and in app/code. Remove them from the production build. If staging needs one, keep it in a separate environment configuration and never in the shared codebase.

3. Protect the API login paths the same way you protect /admin

Whatever you use for /admin, apply it to these paths too:

/rest/*/V1/integration/admin/token
/rest/*/V1/tfa/provider/*

If an ERP, PIM or other system needs an admin token, allow its IP addresses on those paths or put mTLS in front of them. If no system needs an admin token from the internet, block the paths for everyone except the office and the deployment pipeline. Do not protect the whole hostname with Access; that closes the storefront. Protect the specific paths.

4. Strong, unique passwords and non-obvious usernames

The throttle counts per username. An account named admin, administrator or the store name is a known target, and a password shared with another system is a weak one. Give every admin a unique password and a username that is not easy to guess. The default minimum password length is 7 (admin/security/minimum_password_length); raise it. Keep admin/security/admin_account_sharing at 0 so one account cannot be logged in from several places. Remove admin accounts of people and agencies who no longer work with you.

5. Shorten the admin token lifetime

The default is 4 hours. If your integrations request a token at the start of each job, 1 hour is enough and costs nothing. Change it under Services > OAuth > Access Token Expiration.

6. Revoke integration tokens you cannot name

Integration tokens never expire. Open System > Extensions > Integrations and remove every integration you cannot match to a running system. I wrote the same step for Magento 1 stores in Magento 1 security in 2026; the risk is the same on both platforms.

7. Watch the token path in your logs

Repeated POST requests to /rest/*/V1/integration/admin/token or to the /rest/*/V1/tfa/provider/* routes from the same source, or spread over many admin usernames, are a signal. Add an alert on them in your log tooling or in the Cloudflare analytics. Normal integrations produce a steady, low number of such requests from known addresses; anything else should wake someone up.

8. Stay on a current release

The current stable line is 2.4.9, released on 12 May 2026. Security patches arrive on the current line, and the controls described here are the 2.4.x behaviour.

None of these steps depends on a specific bug or CVE. The admin login API is a control surface. The list above makes it reachable only by the people and systems that need it, and makes a password alone useless to everyone else. This kind of admin and API review, checking the 2FA mode, the modules, the edge rules and the token settings, is work I do for store owners, billed by the hour with a fixed scope agreed in advance; the rate is on the pricing page.

FAQ

Does changing my Admin URL hide the admin token endpoint?

No. The Admin URL renames the adminhtml route only. The /rest prefix is fixed and is handled by the Web API front controller through the same pub/index.php as the storefront. /rest/<store>/V1/integration/admin/token stays at the same address on every install.

If 2FA is on, am I safe?

You are much safer. With native 2FA enforced, the generic token endpoint refuses username and password, and the provider endpoints need a one-time code. Check three things: Adobe IMS mode disables native 2FA; a third-party bypass module reopens the generic endpoint; and 2FA works inside the application, so the path is still reachable and the only native throttle is per username. Add the edge rule as well.

Does Cloudflare Access on /admin protect the Magento REST API?

No. An Access application covers a hostname plus a path and the subpaths under it. /rest is not under /admin. Add a second Access application for /rest/*/V1/integration/admin/token and /rest/*/V1/tfa/provider/*, or a WAF rule on those paths.

Can I disable the admin token endpoint?

There is no native configuration flag for it. The route is declared in the Magento_Integration module's webapi.xml on every install. The setting oauth/consumer/enable_integration_as_bearer controls only whether integration tokens may be used as bearer tokens. Restrict the path at the web server, CDN or WAF. Removing the route needs a custom module and is not standard.

Does the admin lockout setting protect the API?

No. admin/security/lockout_failures and admin/security/lockout_threshold are enforced by an observer registered in the adminhtml area, so they apply to the admin login form. The REST endpoint has its own OAuth throttle, oauth/authentication_lock/max_failures_count = 6 failures and oauth/authentication_lock/timeout = 1800 seconds, counted per username.