Secure the server that hosts the REST API
The REST API gives your apps and AI clients access to your Sage 50 company file. Anyone who can reach it with a valid API key can read your accounting data and create or change records such as invoices, payments and journal entries. Protecting the server that hosts it is as important as protecting Sage 50 itself.
This article lists what the REST API already does for you, then what you should do on your side. Most steps are done once, when you set up the server.
What the REST API already does
- Every request needs an API key. A request without a valid key in the
x-api-keyheader is rejected with401. - Each installation gets a strong random key. The installer generates a key with a 32-character random password on a new installation. Updates keep your existing keys.
- Several keys can coexist. You can give each app its own key and revoke one without affecting the others.
- The API runs with limited Windows rights. The REST API and the MCP server each run in their own IIS app pool, with write access only to their own
logsfolder. - Logs do not contain your keys. The installation log masks the Sage 50 password and the API keys, and the MCP log records only which tool ran, how long it took and whether it succeeded.
These protections do not replace the steps below. In particular, keep in mind that:
- An API key gives full access. There are no read-only keys. Any key can read, create, change and delete everything the API exposes.
- The installer creates HTTP endpoints. Over HTTP, the API key and your Sage 50 data travel in clear text on the network. Adding HTTPS is up to you.
- The REST API does not lock out repeated failed attempts. Limiting who can reach the server, or putting a proxy in front of it, is what stops someone from guessing a key.
1. Choose how the API is reached
Expose the REST API no more widely than your apps need. Where the apps that call it run decides how much you open:
| Where the apps run | How they should reach the API |
|---|---|
| On the Sage 50 server itself | Through localhost. Nothing needs to be opened on the network. |
| On computers in your office | Over your private network. Do not publish the API on the internet. |
| On computers outside the office | Through your VPN, so they reach the server as if they were in the office. |
| In a cloud service (SaaS) or a cloud-hosted app | Through an outbound tunnel or a site-to-site VPN if possible, otherwise over the internet with the protections described below. |
When a cloud service must reach the API
Some integrations run in a provider’s cloud and cannot join your private network. Never make the API reachable by simply forwarding a port from your router to the server. Prefer the first two approaches below, which keep the API off the internet. Use the others when neither is possible:
- Use an outbound tunnel. A small agent installed on the Sage 50 server opens an outgoing connection to a relay service, and the cloud app reaches the API through that connection. No inbound port is opened on your firewall and nothing is published on the internet. It also works when the cloud app has no fixed IP addresses. Many cloud platforms and network providers offer this kind of tunnel, often at a low cost. Configure it to reach only the REST API, not the MCP server, and protect the tunnel’s access keys like an API key.
- Connect the provider through a site-to-site VPN. If the provider supports it, the service reaches the server over a private link and nothing is published on the internet. This option often costs more and takes more work to set up than an outbound tunnel.
- Allow only the provider’s IP addresses. Ask the provider for the fixed IP addresses its service calls from, and allow HTTPS only from those addresses at your network firewall. Everyone else on the internet is blocked before reaching the server. This works only if those addresses are reserved for that provider’s service. Many cloud platforms share their outgoing addresses among all their customers, and allowing them would let those customers in as well.
- Put a reverse proxy or web application firewall (WAF) in front of the server. The proxy receives the internet traffic, handles HTTPS with a public certificate, and forwards only the allowed requests to the server. A proxy can also limit the request rate and block addresses that fail authentication repeatedly, which the REST API does not do on its own. Configure it to forward only the paths the service needs, for example the REST API but not the MCP server.
Whatever the approach, also:
- never send requests over plain HTTP on the internet: with an IP allow-list or a reverse proxy, use HTTPS with a certificate from a public certificate authority (see step 3); an outbound tunnel or a VPN encrypts the traffic itself,
- give the service its own API key so you can revoke it alone (see step 4),
- review the logs regularly for unexpected addresses or failed attempts (see step 10).
2. Configure the firewall
Ask your network or security administrator to restrict inbound traffic to the server, both on the network firewall and on Windows Firewall on the server. The REST API and the MCP server are IIS websites and use these ports:
| Port | Protocol | Rule |
|---|---|---|
| 443 | TCP (HTTPS) | Allow only from the sources that need the API: the client computers, your VPN address range, the cloud provider’s IP addresses or your reverse proxy. |
| 80 | TCP (HTTP) | Do not allow from other machines. The MCP server calls the REST API on the same server through http://localhost, which the firewall does not block. |
If your IIS bindings use other ports, apply the same rules to those ports.
An outbound tunnel needs no inbound rule. The agent on the server only needs to make outgoing HTTPS connections to the relay service.
When IIS is installed, Windows usually adds the World Wide Web Services (HTTP Traffic-In) and World Wide Web Services (HTTPS Traffic-In) rules, which allow every address. Restrict or disable them, otherwise they let in traffic your own rules were meant to block. If the server hosts other websites, check with whoever manages them first.
3. Use HTTPS for connections from other machines
The installer creates HTTP endpoints, for example http://localhost/Sage50RestApi/. HTTP is fine when the app or AI client runs on the server itself, because the traffic never leaves the machine. As soon as a request comes from another machine, use HTTPS so that the API key and your data are encrypted on the network.
The Base64 encoding of the API key is not encryption. Anyone who sees the x-api-key header on the network can decode the key in seconds. HTTPS is what protects it.
To add HTTPS, your IT team gets a certificate for the server name your clients use, for example sage50.company.local, and adds an https binding with it to the IIS website that hosts the REST API, for example Default Web Site. Then point your apps and AI clients to the HTTPS URL, for example https://sage50.company.local/Sage50RestApi/.
Clients must trust the certificate. For computers on your network, it can come from your company’s certificate authority. A cloud service reaching the API over the internet needs a certificate from a public certificate authority, on the server or on your reverse proxy.
Keep the existing HTTP binding. The MCP server calls the REST API on the same server through http://localhost, and that call never leaves the machine. To stop other machines from using HTTP, block port 80 in the firewall as described in step 2 instead of removing the binding.
Also ask your IT team to:
- Allow only TLS 1.2 and later. Older versions of Windows Server still accept TLS 1.0 and 1.1 and some weak ciphers. Disable them on the server, or on your reverse proxy if you use one.
- Plan the certificate renewal. Certificates expire, often after one year. Note the expiry date and renew the certificate before it, otherwise every app on another machine stops connecting. Do not switch back to HTTP to work around an expired certificate.
4. Give each app its own strong API key
An API key has two parts, an identifier and a password, written identifier:password. Your apps send it Base64-encoded in the x-api-key header. The REST API reads its list of valid keys from the ApiKeys setting in its Web.config file, separated by semicolons:
<add key="ApiKeys" value="invoicing:Kd8...;reporting:p2Q...;claude-finance:Zx7..." />
Give each app, integration and AI client its own key, with an identifier that names the app it belongs to. When an app is retired or a key leaks, you know which entry to remove, and nothing else stops working. The identifier is not written to the IIS logs, so the logs cannot tell you which key made a given request.
Use long passwords, of at least 32 random characters, like the key the installer generates. Updates keep existing keys, so an installation first made with an older installer may still have a shorter key. If yours is shorter than 32 characters, replace it.
The safest way to create and keep a key is your organization’s password manager, for example Bitwarden, 1Password or Keeper:
- Create an entry for the app, named after its identifier, for example Sage 50 REST API – invoicing.
- Use the password manager’s generator to create a password of at least 32 characters with letters and numbers only. Symbols such as
;,:,&,<or"would break theApiKeysvalue inWeb.config. - Store the full
identifier:passwordvalue and its Base64-encoded version in the entry, and share the entry only with the people who configure that app.
The app sends the key Base64-encoded in the x-api-key header. Do the encoding on a trusted computer, never with an online encoder website, since that would send your key to a third party. The key then lives in the password manager, in Web.config and in the app, and not in emails, chat messages or documents.
To edit the keys:
- In IIS Manager, select the REST API application, for example Sage50RestApi, and click Explore in the Actions pane to open its folder.
- Open
Web.configin Notepad as an administrator. - Add, replace or remove entries in the
ApiKeysvalue, keeping them separated by semicolons, then save.
IIS applies the change on its own within a few seconds. The MCP server checks keys against the REST API, so it uses the same list and needs no change. To test a key without touching Sage 50, call GET /api/auth/check with it: it returns 401 if the key is not valid.
Updates keep the ApiKeys value as it is, so your keys survive a new version of the REST API.
5. Rotate keys when people or exposure change
Replace a key when:
- someone who knew it leaves the company or changes role,
- it was sent by email or chat, pasted into an AI conversation, shown in a screenshot or saved in a shared document or a code repository,
- people other than administrators could sign in to the server and read its files.
To rotate a key, add the new key first, update the app with it, check that the app works, then remove the old key. The app keeps working throughout.
If a key may have leaked
When you suspect someone else has a key, do not wait for a planned rotation:
- Remove the key from
ApiKeysright away, even if the app stops working until you give it a new key. - Check the IIS logs for requests from addresses you do not recognize since the key may have leaked (see step 10).
- In Sage 50, review the entries created or changed by the Sage 50 user of the API over the same period.
- If
Web.configitself may have been read, replace every key it contains and change the password of the API’s Sage 50 user.
6. Limit who can sign in to the server
Web.config holds the API keys and the Sage 50 user name and password in plain text. Windows file permissions are what protect them. Anyone who can sign in to the server and read the installation folder can read them too.
- Allow only administrators to sign in to the server, locally or through Remote Desktop. Do not use it as a shared workstation.
- Do not share the installation folder on the network.
- If other users must sign in to the server, ask your IT team to check the permissions of the REST API folder, including
Web.configandlogs. Only Administrators, SYSTEM and the IIS app pools of the REST API and MCP server need access.
To see who can read Web.config, open its Properties and look at the Security tab, or use the icacls command. If the list includes Users, Everyone or Authenticated Users, ordinary accounts on the server can read your keys.
Protect the administrator access itself:
- Never make Remote Desktop reachable from the internet. Administrators connect through the VPN.
- Use multi-factor authentication for administrator accounts where your environment supports it.
- Keep antivirus or endpoint protection active on the server.
- If the company file is on a network share, the REST API runs under a Windows service account that can read the share. Use a dedicated account for this, not an administrator or a person’s account, with access to that share only.
Protect backups and snapshots
Backups of the server and virtual machine snapshots contain Web.config, and so the API keys and the Sage 50 password in plain text. Store them where only administrators can read them, with the same care as the server itself.
7. Use a dedicated Sage 50 user for the API
The installer asks for a Sage 50 user name and password, which the REST API uses to open the company file. Create a dedicated Sage 50 user for this purpose instead of reusing a person’s account:
- Changes made through the API are then easy to tell apart from changes made by your staff.
- Nobody signs in to Sage 50 with that password, so it is not typed, shared or changed by accident.
- When an employee leaves, you disable their own Sage 50 account without breaking your integrations.
Give it a strong password. If you restrict the rights of this user in Sage 50, test your apps afterwards to make sure the operations they need still work.
8. Protect API keys in AI clients
AI clients connect to the MCP server with the same kind of API key as your apps, and MCP lets the model create invoices and payments, not only read data.
- In Claude Desktop, enter the key in the extension’s REST API key field. Claude Desktop stores it in its secure configuration storage. See Set up Claude Desktop with the Sage 50 MCP server.
- In other clients, keep the key in an environment variable or a protected user-level configuration file, not in a project file that is shared or committed to a repository. See Connect AI clients to Sage 50.
- Never paste the key into a chat with the AI.
- Give each person’s AI client its own key, so you can revoke one person’s access without affecting the others.
Keep approval on for changes
An AI model reads your Sage 50 data to answer questions, and that data can contain text written by others, such as a customer note or an imported description. Text crafted for the purpose can trick the model into calling a tool you did not ask for, for example creating a payment. This is called prompt injection.
Most AI clients ask for your approval before they run a tool. Keep that approval on for every tool that creates, changes or deletes data, and read what the AI is about to do before you approve it. Do not set those tools to run automatically.
9. Keep everything up to date
- REST API. Security fixes reach your server only through a new installer. Install new versions when we send them. See Update the REST API to a new version.
- Windows and IIS. Apply Windows updates to the server regularly. IIS is updated through Windows Update.
- Sage 50. Keep Sage 50 at a version supported by your REST API.
10. Review the logs from time to time
- IIS logs, by default in
C:\inetpub\logs\LogFiles, list every request with its source address and status code. Many401responses from the same address mean someone is trying keys. Requests from an address you do not recognize mean the firewall lets in more machines than you expect. - MCP log, in the
logsfolder of the MCP server installation, in theoperations.jsonlfile. It lists which tools AI clients ran and when.
The REST API deletes its own logs after 30 days. If you need to keep a longer history, copy them elsewhere before then.
Checklist
| Done | Recommendation |
|---|---|
| ☐ | The API is reached only through the private network or VPN, or, for a cloud service, through an outbound tunnel, a site-to-site VPN, an IP allow-list or a reverse proxy. |
| ☐ | The firewalls allow port 443 only from the sources that need the API, and block port 80 from other machines. |
| ☐ | Connections from other machines use HTTPS with a trusted certificate, TLS 1.2 or later only. |
| ☐ | The certificate expiry date is noted and its renewal planned. |
| ☐ | Each app and AI client has its own key of at least 32 random characters. |
| ☐ | Keys are rotated when people leave or a key may have been exposed, and you know what to do if one leaks. |
| ☐ | Only administrators can sign in to the server and read Web.config. Remote Desktop is not reachable from the internet. |
| ☐ | Backups and snapshots of the server are protected like the server itself. |
| ☐ | The REST API uses a dedicated Sage 50 user. |
| ☐ | AI client keys are stored in secure settings or environment variables. |
| ☐ | AI clients ask for approval before creating, changing or deleting data. |
| ☐ | The REST API, Windows and Sage 50 are up to date. |
| ☐ | IIS and MCP logs are reviewed regularly. |