Skip to content

Safety and limits ​

A tool changes real data, so the library is strict where a mistake would hurt. This page says what it does by itself, what stays your job, and what this version cannot do.

What a request passes ​

Who is asking?auth:May they openthis tool?allow:Is the form ours?asked when a form comesin: it carries a tokenYour script runsfrom top to bottomevery request, also a clickyesnoyesnoyesnoRefusednobody is logged inRefused"Not allowed"Refuseda forged requestThe page
What a request passes before a line of your script runs. A page that is only opened sends no form, so the third question is not asked of it.

The first two questions are asked on every request, also when a page only refreshes itself. The third is asked whenever a form comes in: a changed input, a pressed button, an upload, a refresh. A page that is only opened sends no form. Only after that does the first line of your script run.

What the library does ​

This list is the one of the README, word for word.

  • No login check, no outside access. Without auth, tools only answer to a browser on the computer they run on. The request must come from a loopback address, with a local host name, and must not look passed on (proxy headers, HTTP/1.0, Connection: close). No check of this kind can see through every proxy or tunnel, so anything that can be reached from outside needs auth.
  • A tool can be closed to some users. allow: is asked before anything of a tool runs, on every request, and only a plain true opens the tool. Without allow: every tool is open to everybody who gets past the login check. Both checks are settings of serve(): a tool file that the web server runs by itself knows nothing of them, which is why the folder of tools stays out of the web root.
  • What a tool keeps belongs to one user. The inputs, the uploaded files and the messages that the library keeps in a session are dropped when the login check names another user in that session, as after a login without a logout before it. The forms of the user before are not taken any more. The library knows a user by the name the login check gives: a text, a number, or an object that says who it is (getUserIdentifier(), getAuthIdentifier() or __toString()). A login check that returns true, an array or another object names nobody, and then the users of one session cannot be told apart.
  • Forged requests are refused. Every form carries a token. A button only counts on a form that was sent from the page itself. The "Reset" link carries a code of its own.
  • Everything is escaped. Labels, table cells and messages are text, never HTML. Output printed with echo is shown as text too.
  • A strict Content-Security-Policy on every page: no inline styles, no inline handlers, nothing from other sites, no framing.
  • A download is a file, never a page. It is sent with the order to save it, never as HTML or a script, and it may do nothing if it is opened in the browser after all. Its name is made safe, also when it contains something a user typed. In CSV that the library writes, formula cells are defused. Every download goes to the log with the name and the size of the file. When the log cannot be written (the log callback throws or returns false), the file is not sent.
  • An uploaded file is out of reach. It lies under a random name that says nothing about it, in a folder that only the PHP user reads. (That holds for the library's own folder on Linux and macOS. A folder you name with uploads: is as closed as you made it.) The page names it by a random handle that is not that name and only counts for the session, the tool and the field the file was uploaded to. No request can name a path, a file of another user or a file of another tool. The name the user gave is cleaned before it is shown or logged, and it is never used on the disk. The library does not serve uploads and does not run them.
  • A page that refreshes changes nothing. A run that the page starts by itself presses no button, takes no file and saves nothing, whatever its request says. It needs the token of the form like every other run.
  • Selections come from your data. table() returns rows from the array you passed in. The browser only says which rows are ticked, and a tick never moves to another row or another table. A row that the search of a table hides is not returned, and the search reads only the columns that are shown.
  • A query gets nothing straight from the browser. A table that reads its pages through a function hands that function a search text to bind as a parameter, a sort value out of your own sortable: list, and a limit and an offset that are whole numbers. A form cannot name another column, and a page that is not there ends at one that is.
  • A column you leave out stays out. What a table puts into the page about a row, besides the cells it shows, is made with a secret that never leaves the session. Neither the id of a row nor a column you left out with columns: can be read from the page, or guessed by trying values against it.
  • Files are found by listing the folder. An address can never point outside it.
  • Error details stay private. They are shown only while no login check is set, because then nobody but your own computer gets in. With a login check they go to the error log unless you pass debug: true. PHP warnings and notices are kept out of the page in the same way.

What stays your job: decide who may open which tool (allow:) and who may do what inside one (user() tells you who is asking), and never change data outside an if (button(...)) block, because the script also runs on every plain page view.

Before colleagues get in ​

  1. Set auth:. Without a login check the tools answer only on the computer they run on.
  2. Keep the folder of tools out of the web root. Only the one script that calls serve() lies where the web server looks for files. Then try the address of a tool file: /tools/refund.php has to answer 403 or 404.
  3. Set allow: when not every tool is for everybody who can log in.
  4. Change data only inside if (button(...)). The script also runs when somebody changes a filter, and when a page refreshes by itself.
  5. Set log: and keep the entries. They say who pressed what, with which inputs.
  6. Leave debug: off on the server. With a login check, error details go to the error log and not into the page.
  7. Keep uploads small. Set maxSize: and PHP's own limits as low as your tools need.
  8. In a framework: end a run with stop() and never with exit. In Laravel, take the route out of the CSRF check and add ->block(). Inside your application says why.

Limits of this version ​

Also word for word from the README. What comes next says which of them may go.

  • Uploads have no progress bar, and cannot be resumed or stopped once they are on their way. A field holds up to 20 files and a session 200. The kind of a file is judged by the ending of its name only.
  • Nothing limits the bytes that uploads take on the disk, only their number: a session keeps up to 200 files of the size you allow, for a day at most. Somebody who is logged in and means harm can use that. Keep maxSize: and PHP's limits as low as your tools need.
  • Uploaded files wait in PHP's temp folder unless you set uploads:. They are closed to other system users, but another PHP application that runs as the same user can read them.
  • While a tool works on a request, PHP holds the session, and other requests of the same user wait. That shows with a large upload that a tool reads for a long time.
  • A table gets all its rows from the script and searches, sorts and pages them itself, on every run. That is quick up to about twenty thousand rows: on a laptop a search took 0.1 seconds, and so did sorting by a text column. For more, pass a function and let the database search, sort and cut the pages.
  • A table that reads its pages through a function keeps ticks for the page on the screen only. It has no "filtered from" count, and it decides by the rows of one page which columns hold numbers.
  • multiselect() is a group of tick boxes. It has no search and no "select all", so it suits lists of up to a few dozen options. The ticks of one field are remembered between page views up to 8 KB of option values. Beyond that the next page view starts from the default again.
  • A message of field_error() is gone with the next run, unless the script says it again. Nothing keeps a note under its field until that field is corrected: check on every run for that. Only inputs can be marked, not a table and not a button.
  • Every tab of tabs() runs on every run. There is no way yet to run only the open one, and a link cannot open a tab or an expander.
  • refresh() runs the whole script and swaps the whole content. There is no way yet to refresh one part of a page, and the server pushes nothing: the page asks. When something above the place you look at grows or shrinks, the page moves under your eyes.
  • progress() shows two numbers that the tool has. The library has no queue and no worker, cannot stop a task and does not work out the time that is left. A bar moves when the page runs again, which refresh() does every two seconds at best.
  • Charts are bar and line charts with one axis and at most 8 series.
  • State lives in the session: PHP's own, or the one you pass to respond() with session:. Two browser tabs of the same tool share saved inputs. A session remembers the inputs of the 50 tools that were used last.
  • A script that runs on its own (without serve()) is told apart by its file and its path. Tools that share both and differ only in the query string (index.php?page=refund) work, but they do not remember their inputs separately.

Released under the MIT License.