← All articles

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

These protections do not replace the steps below. In particular, keep in mind that:

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:

Whatever the approach, also:

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:

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:

  1. Create an entry for the app, named after its identifier, for example Sage 50 REST API – invoicing.
  2. 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 the ApiKeys value in Web.config.
  3. Store the full identifier:password value 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:

  1. In IIS Manager, select the REST API application, for example Sage50RestApi, and click Explore in the Actions pane to open its folder.
  2. Open Web.config in Notepad as an administrator.
  3. Add, replace or remove entries in the ApiKeys value, 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:

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:

  1. Remove the key from ApiKeys right away, even if the app stops working until you give it a new key.
  2. Check the IIS logs for requests from addresses you do not recognize since the key may have leaked (see step 10).
  3. In Sage 50, review the entries created or changed by the Sage 50 user of the API over the same period.
  4. If Web.config itself 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.

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:

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:

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.

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

10. Review the logs from time to time

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.

Next steps