« MBS FileMaker Plugin,… | Home | MBS @ FMTraining.TV -… »

Secure your FileMaker solution: scripts, Evaluate and MBS Plugin

When we talk about security in FileMaker, most people think of accounts, privilege sets and encryption at rest. All important. But there are two blind spots we see again and again in solutions we review:

  1. Developers assume a script only runs from the button they placed on a layout.
  2. Developers treat Evaluate() as a harmless helper.

Both assumptions can be exploited to read data a user should never see, or to call plugin functions the developer never intended to be called. Let’s look at both and then at the tools MBS FileMaker Plugin offers to reduce what an attacker can do with the plugin.

Any script can run at any time

You built a script Delete Invoice, and it is attached to a button on the invoice layout, which only shows for managers. So the script is safe, right?

No. A script can be started in many ways:

  • From the Scripts menu, if the script is set to show there.
  • Via the FileMaker Data API or OData, with any script parameter the caller chooses.
  • Via an fmp:// URL with a script name and parameter.
  • With Perform Script on Server from another script.
  • From another file which has access to this one.
  • Through a script trigger on a layout or object you forgot about.
  • Through a plugin, e.g. MBS("FM.RunScript"; Get(FileName); "Delete Invoice"; $param) called in a calculation somewhere.

The layout, the window, the current record, the found set and the parameter may all be different from what you expect. So each script that does something sensitive should check its context first and exit early if anything looks wrong:

# Delete Invoice
# only managers
If [ Get ( AccountPrivilegeSetName ) ≠ "Manager" ]
    Exit Script [ Text Result: "not allowed" ]
End If
# only from our layout in FileMaker Pro, not from Data API or server
If [ Get ( LayoutName ) ≠ "Invoice Detail" or PatternCount ( Get ( ApplicationVersion ) ; "Pro" ) = 0 ]
    Exit Script [ Text Result: "wrong context" ]
End If
# validate the parameter
Set Variable [ $id ; Value: JSONGetElement ( Get ( ScriptParameter ) ; "InvoiceID" ) ]
If [ IsEmpty ( $id ) or Filter ( $id ; "0123456789" ) ≠ $id ]
    Exit Script [ Text Result: "invalid parameter" ]
End If
# ... do the work

Useful functions for such checks:

  • Get(AccountName) and Get(AccountPrivilegeSetName) – who is calling?
  • Get(ApplicationVersion) – Pro, Go, WebDirect, Server or the Data API engine?
  • Get(LayoutName), Get(WindowName), Get(FoundCount), Get(RecordID) – where are we?
  • Get(ScriptParameter) – validate every value before you use it.

Privilege sets remain your first line of defense. Whatever a privilege set can’t do, a script running with that account can’t do either (unless you enabled Run script with full access privileges – check those scripts twice!). The account may be the guest account.

Every Evaluate() is an injection point

You probably know SQL injection: user input gets concatenated into a SQL statement and suddenly the input becomes part of the code. The same applies to FileMaker’s Evaluate() function.

Take this helper, which returns a field value for a field name passed as script parameter, e.g. from a Data API call:

Set Variable [ $field ; Value: Get ( ScriptParameter ) ]
Set Variable [ $value ; Value: Evaluate ( "Invoices::" & $field ) ]
Exit Script [ Text Result: $value ]

The developer expects Total or Customer. But an attacker can pass:

Total & ¶ & Get ( AccountName ) & ¶ & MBS ( "Files.List" ; "/" )

Now the script returns the total, the account name and the directory listing of the server’s root folder. With other calls the attacker could read other tables via ExecuteSQL, query Get() functions with internal information, or call any of the 7000+ plugin functions: write files, run shell commands with Shell.Execute, send data out with CURL.Perform or start other scripts with FM.RunScript.

The same pattern hides in many places:

  • Evaluate() on text from fields, script parameters, JSON or imported data.
  • Let() or calculations assembled as text and passed to Evaluate.
  • ExecuteSQL() or MBS("FM.ExecuteFileSQL") with values concatenated into the SQL statement.
  • Formulas stored in records (“custom calculations”) that users can edit.

What to do:

  • Avoid Evaluate on user input. Often there is a better way. For a dynamic field reference use GetField(), which only resolves a field name and doesn’t evaluate an expression.
  • Whitelist instead of blacklist. If you expect a field name, check it against a list of allowed names. If you expect a number, check that it only contains digits.
  • Use Quote() if you really must embed user text as a literal into a calculation string: Evaluate ( "Upper ( " & Quote ( $text ) & " )" ).
  • Use parameters for SQL. Pass values as ? parameters to ExecuteSQL or FM.ExecuteFileSQL instead of building the statement with &.
  • Validate and filter input everywhere it enters your solution: layouts, Data API, imports, URLs, web viewers.

Know which plugin functions you use

Even with careful coding you may have a weak spot somewhere. So let’s make sure that a successful injection can’t do much with the plugin. The first step is to learn which MBS functions your solution actually uses.

MBS("Plugin.UsedFunctions") returns the list of plugin functions called since the plugin was loaded in this FileMaker process. MBS("Plugin.UsedFunctionCounts") returns the same as JSON with a call count for each function.

A single run tells you little, since one user may never print, never send email or never run the year-end scripts. So collect the data over time:

  1. Create a table PluginUsage with fields for timestamp, account, client type (Get(ApplicationVersion)), platform and the function list.
  2. In your close script (OnLastWindowClose) and in a scheduled server script, create a record with MBS("Plugin.UsedFunctions").
  3. Let this run for a few weeks with all users and all client types: FileMaker Pro on Mac and Windows, FileMaker Go, WebDirect, server schedules, Perform Script on Server and Data API.
  4. Aggregate the list, e.g. with a calculation like:
UniqueValues ( ExecuteSQL ( "SELECT Functions FROM PluginUsage" ; "" ; ¶ ) )

Now you have the list of functions your solution needs. Compare it with what you expect and review anything surprising.

Lock down the plugin in your start script

With the list, you can restrict the plugin in the start script of your solution. These settings are not permanent, so they must run each time the plugin is loaded. Make sure the start script runs on all clients, including server-side scripts and Data API sessions.

Plugin.LimitToFile

MBS("Plugin.LimitToFile"; FileList) limits all plugin calls to the given files. The names must match Get(FileName) exactly (case sensitive). Calls from any other file get an error – they can’t even query the plugin version. This is especially useful on a server hosting several solutions, maybe from different customers.

Plugin.LimitFunction

MBS("Plugin.LimitFunction"; Name; PrivilegeSets; AccountNames; ScriptNames; FileNames) restricts a single function, so it can only be called by certain privilege sets, accounts, scripts or files. Leave a list empty if you don’t need it. If you pass several lists, all of them must match, e.g. privilege set “Manager” and the script “Run Backup”. Script names are given as file name, colon and script name, e.g. "Invoices:Export Backup". Once a function is limited, the limits can’t be changed again until the plugin is reloaded.

Use it for powerful functions you need, but only in one or two places: Shell.Execute, Files.List, Text.WriteTextFile, Container.WriteFile, FM.RunScript or FM.ExecuteFileSQL. Limiting a function to the one script that needs it is a strong restriction: an injection in some other calculation can no longer call it. Combine it with a privilege set to also make sure only the right people run that script.

Plugin.SetFunctions

MBS("Plugin.SetFunctions"; FunctionList) reduces the plugin to the functions in the list. Everything else is gone until the plugin is reloaded. Entries can end with a * as wildcard, e.g. JSON.* for all JSON functions. You can only shrink the list – calling SetFunctions again can’t bring back a removed function.

Call it last and don’t include the Plugin.* configuration functions in the list. That way nobody can change the file list or the function limits later.

Example start script

# MBS lockdown, runs in OnFirstWindowOpen
If [ MBS ( "IsRegistered" ) ≠ 1 ]
    Set Variable [ $r ; Value: MBS ( "Register" ; ... ) ]
End If
# 1. only our files may use the plugin
Set Variable [ $r ; Value: MBS ( "Plugin.LimitToFile" ; "Invoices¶Contacts¶Assets" ) ]
# 2. limit dangerous functions to the scripts which need them
Set Variable [ $r ; Value: MBS ( "Plugin.LimitFunction" ; "Shell.Execute" ; "[Full Access]" ; "" ; "Invoices:Run Backup" ) ]
Set Variable [ $r ; Value: MBS ( "Plugin.LimitFunction" ; "Text.WriteTextFile" ; "" ; "" ; "Invoices:Export Data¶Invoices:Write Log" ) ]
# 3. reduce to the functions we use, as last step
Set Variable [ $r ; Value: MBS ( "Plugin.SetFunctions" ;
    "IsRegistered¶Version¶Plugin.UsedFunctions¶" &
    "JSON.*¶CURL.*¶" &
    "Shell.Execute¶Text.WriteTextFile¶" &
    "DynaPDF.*" ) ]
If [ MBS ( "IsError" ) ]
    # log the error
End If

Test this in a copy of your solution first. If you forgot a function, the call returns an error instead of a result. So keep logging plugin errors, e.g. with Plugin.SetErrorScriptTrigger or Trace, for a while after enabling the lockdown, and extend the list where needed.

Summary

  • Assume every script can be called at any time, from anywhere, with any parameter.
  • Check account, privilege set, client type, layout and parameters at the start of sensitive scripts.
  • Treat every Evaluate() like a SQL statement: never feed it unvalidated input.
  • Prefer GetField(), whitelists, Quote() and SQL parameters.
  • Log Plugin.UsedFunctions over weeks and across all users and clients.
  • Use Plugin.LimitToFile to keep other files on the server away from the plugin.
  • Use Plugin.LimitFunction for powerful functions like Shell.Execute.
  • Use Plugin.SetFunctions as last step in your start script, without the Plugin.* functions.

Nobody wants someone to call an MBS function through an Evaluate and extract or compromise data. With a few checks in your scripts and a few lines in your start script, you make that a lot harder. If you have questions, please don’t hesitate to contact us.

This article was outlined by an human and improved by AI. Claris FileMaker Plugin
05 11 26 - 11:49