Securing the SonicOS API: CORS and Bearer Token Session Check

Description

Field

Detail

Applies to

SonicWall firewalls running SonicOS / SonicOSX with the SonicOS API enabled

Version

SonicOS 7.3.4 and later [confirm equivalent build for Gen8 and other maintained branches]

Setting location

Device | Settings | Administration | SonicOS API

 

In short

SonicOS 7.3.4 gives you direct control over how the SonicOS API handles requests from web browsers and how API sessions are authenticated

Two settings matter: CORS, which is now disabled by default with an explicit list of allowed origins, and Non-GUI Management Login Bearer Token Session Check, which is now enabled by default.

If you are upgrading from an earlier release, check both settings after the upgrade. Your previous configuration may be carried forward rather than taking the new defaults.

Where to find these settings

  • Log in to the SonicOS web management interface and navigate to Device | Settings | Administration | SonicOS API
  • The two settings described in this article are highlighted below.

    Figure 1 — The SonicOS API page in SonicOS 7.3.4. The two settings covered in this article are (1) CORS and Allow CORS Origins, and (2) Non-GUI Management Login Bearer Token Session Check. Both are shown enlarged in Figures 2 and 3.

CORS and Allow CORS Origins

Figure 2 — CORS is disabled by default. The Allow CORS Origins field defines the exceptions.

What the setting does

Enables or disables Cross-Origin Resource Sharing (CORS), which permits or blocks web pages from a different domain accessing this firewall’s resources.

When CORS is enabled, SonicOS requires an explicit allow list of permitted origins rather than allowing all origins. You enter these in the Allow CORS Origins field as IP addresses or domain names, including wildcard subdomain patterns. This gives you control over which external sites, if any, may make cross-origin API calls to the firewall.

In plain terms

Web browsers normally stop a page on one website from reading data from another website. That protection is what keeps a page you happen to open from quietly talking to your firewall.

  • CORS disabled (default): the firewall does not grant any external website permission to read its API responses. This is the recommended setting.
  • CORS enabled with specific origins listed: only the websites you name may make cross-origin API calls. Use this when you have a legitimate web application that needs to call the API from a browser.
  • CORS enabled with no origins listed: not recommended. Enable CORS only together with a specific allow list.

When you need to enable it

Most customers do not. Leave CORS disabled unless you operate a browser-based application that calls the SonicOS API directly. Scripted and server-side integrations do not need CORS at all — see “Will this affect my API integrations?” below.

How to configure allowed origins

  1. Navigate to Device | Settings | Administration | SonicOS API.
  2. Set CORS to enabled.
  3. In the Allow CORS Origins field, enter each permitted origin on its own line. You may use an IP address, a fully qualified domain name, or a wildcard subdomain pattern.
  4. Click Accept.
  5. Test your application. If it still cannot reach the API, confirm the origin you entered matches exactly what the browser sends, including the scheme and any port.

Keep the list as short as possible. Every entry is a website you are trusting to make authenticated calls to your firewall.

Non-GUI Management Login Bearer Token Session Check


Figure 3 — Non-GUI Management Login Bearer Token Session Check is enabled by default in SonicOS 7.3.4.

What the setting does

This option applies to non-GUI management login. The bearer token is checked for every API request call. The token is initially obtained from the /auth API response. The API client must include this bearer token in the HTTP header for all API requests after logging in. This setting is enabled by default in SonicOS 7.3.4.

In plain terms

With this setting enabled, every API request must carry its own proof that it belongs to a logged-in session. It is not enough for the request simply to come from the same computer that logged in earlier.

This matters because a web page open in a browser sends requests from the same computer as your management session. Requiring a token on each request means such a page cannot act on your session, because it has no way to obtain the token.

  • SonicWall recommends leaving this setting enabled.
  • If you disable it, API requests are associated with the session by source IP address alone, which is considerably weaker.

What your API client needs to do

  1. Authenticate to the /auth endpoint as normal.
  2. Read the bearer token from the /auth response.
  3. Include that token in the HTTP header of every subsequent API request for the life of the session.
  4. Obtain a fresh token when you re-authenticate.

Most SonicWall-supplied and third-party API clients already do this. If you maintain your own client and it does not yet send the token, update it before disabling the setting — do not disable the setting as a shortcut.

Why these defaults are set this way

In earlier releases, an API session was associated with the source IP address of the administrator’s workstation, and API responses permitted cross-origin access without restriction. In combination, these two behaviors meant that a web page open in an administrator’s browser could issue API requests that the firewall accepted as part of the active management session.

The two settings described above close that gap. The bearer token check ensures each request proves it belongs to the session. Disabling CORS by default ensures the firewall does not grant external websites permission to read API responses.

Recommended configuration

Setting

Recommended

Notes

SonicOS API

Disabled if unused

The API is enabled by default. If no integration depends on it, turn it off.

CORS

Disabled

Enable only if a browser-based application must call the API, and always with a specific allow list.

Allow CORS Origins

Empty, or minimal

Only required when CORS is enabled. List only origins you trust.

Non-GUI Management Login Bearer Token Session Check

Enabled

Default in 7.3.4. Leave enabled.

Session security using RFC-7616 Digest authentication

Consider enabling

Provides additional session binding for Digest authentication. Test with your clients first.

RFC-2617 HTTP Basic Access authentication

Disabled

Basic authentication transmits credentials with minimal protection. Default is disabled.

After upgrading — what to check

Upgrading does not necessarily apply the new defaults. Where a configuration is carried forward, previous values may be preserved. Verify both settings after the upgrade rather than assuming them.

  1. Navigate to Device | Settings | Administration | SonicOS API.
  2. Confirm CORS is disabled. If it is enabled and you do not require it, disable it and click Accept.
  3. If you do require CORS, confirm the Allow CORS Origins field lists only the origins you intend to trust.
  4. Confirm Non-GUI Management Login Bearer Token Session Check is enabled. If it is disabled, enable it and click Accept.
  5. If the SonicOS API is not used in your environment, consider disabling it entirely.
  6. Repeat on every managed firewall. Where you manage firewalls through Network Security Manager, verify the settings across the estate rather than unit by unit.

Will this affect my API integrations?

Integration type

Effect

curl, Postman, Python, PowerShell and other scripted clients

Not affected by the CORS setting. These clients are not browsers and do not rely on cross-origin permissions. They must send the bearer token, which most already do.

Network Security Manager and SonicWall management platforms

Not affected.

Your own web application that calls the API from a browser

May be affected. Enable CORS and add your application’s origin to the Allow CORS Origins list. Ensure the client sends the bearer token on every request.

Captive portal or guest login pages that call the API from a browser

May be affected. Test in a lab before upgrading production firewalls, and add the origin to the allow list if required.

Local development against a firewall (for example a UI running on localhost)

Enable CORS and add the development origin to the allow list for the duration of the work. Remove it afterwards.

Frequently asked questions

  • Do I need to enable CORS for my automation scripts to work?
  • No. CORS is a browser mechanism. Scripts, scheduled jobs and server-to-server integrations are unaffected by it.
  • I enabled CORS and my web application still cannot reach the API. Why?
    The origin must match exactly what the browser sends, including the scheme and any non-standard port. Check the browser developer console for the blocked origin and compare it with your entry. Also confirm the client is sending the bearer token.
  • Can I use a wildcard in Allow CORS Origins?
    Wildcard subdomain patterns are supported. Use the narrowest pattern that works for your application.
  • Can I turn off the bearer token check to simplify my client?
    It is possible but not recommended. Doing so returns the firewall to associating API sessions with the source IP address alone. Update the client to send the token instead.
  • Where does my client get the bearer token?
    From the /auth API response at login. The client then includes it in the HTTP header of every subsequent request.
  • Does this affect administrators using the web UI?
    No. These settings apply to the SonicOS API and non-GUI management login. Normal web UI administration is unchanged.

Related Articles

  • Mobile Connect is becoming NetExtender
    Read More
  • How to setup the SonicWave 600 series on WNM
    Read More
  • How can I configure VLANs in SonicWall NSv GEN7 and above?
    Read More
not finding your answers?