diff --git a/docs/integrations/nginx.rst b/docs/integrations/nginx.rst index 25ce6ca98..2dc7755b8 100644 --- a/docs/integrations/nginx.rst +++ b/docs/integrations/nginx.rst @@ -35,37 +35,6 @@ The first step is to create an Nginx configuration file that proxies requests to For ubuntu, if you already installed nginx through :code:`apt` you can add this to the config file in :code:`/etc/nginx/sites-enabled/default`. -.. _block_fulltable: - -Block Full-Table Operations ---------------------------- - -Each table in the admin-selected schema gets exposed as a top level route. Client requests are executed by certain database roles depending on their authentication. All HTTP verbs are supported that correspond to actions permitted to the role. For instance if the active role can drop rows of the table then the DELETE verb is allowed for clients. Here's an API request to delete old rows from a hypothetical logs table: - -.. tabs:: - - .. code-tab:: http - - DELETE /logs?time=lt.1991-08-06 HTTP/1.1 - - .. code-tab:: bash Curl - - curl "http://localhost:3000/logs?time=lt.1991-08-06" -X DELETE - -However it's very easy to delete the **entire table** by omitting the query parameter! - -.. tabs:: - - .. code-tab:: http - - DELETE /logs HTTP/1.1 - - .. code-tab:: bash Curl - - curl "http://localhost:3000/logs" -X DELETE - -This can happen accidentally such as by switching a request from a GET to a DELETE. To protect against accidental operations use the `pg-safeupdate `_ PostgreSQL extension. It raises an error if UPDATE or DELETE are executed without specifying conditions. To install it you can use the `PGXN `_ network: - .. code-block:: bash sudo -E pgxn install safeupdate diff --git a/docs/integrations/pg-safeupdate.rst b/docs/integrations/pg-safeupdate.rst new file mode 100644 index 000000000..c5f0928cd --- /dev/null +++ b/docs/integrations/pg-safeupdate.rst @@ -0,0 +1,42 @@ +pg-safeupdate +############# + +.. _block_fulltable: + +Block Full-Table Operations +--------------------------- + +If the :ref:`active role ` can delete table rows then the DELETE verb is allowed for clients. Here's an API request to delete old rows from a hypothetical logs table: + +.. tabs:: + + .. code-tab:: http + + DELETE /logs?time=lt.1991-08-06 HTTP/1.1 + + .. code-tab:: bash Curl + + curl "http://localhost:3000/logs?time=lt.1991-08-06" -X DELETE + +Note that it's very easy to delete the **entire table** by omitting the query parameter! + +.. tabs:: + + .. code-tab:: http + + DELETE /logs HTTP/1.1 + + .. code-tab:: bash Curl + + curl "http://localhost:3000/logs" -X DELETE + +This can happen accidentally such as by switching a request from a GET to a DELETE. To protect against accidental operations use the `pg-safeupdate `_ PostgreSQL extension. It raises an error if UPDATE or DELETE are executed without specifying conditions. To install it you can use the `PGXN `_ network: + +.. code-block:: bash + + sudo -E pgxn install safeupdate + + # then add this to postgresql.conf: + # shared_preload_libraries='safeupdate'; + +This does not protect against malicious actions, since someone can add a url parameter that does not affect the result set. To prevent this you must turn to database permissions, forbidding the wrong people from deleting rows, and using `row-level security `_ if finer access control is required. diff --git a/postgrest.dict b/postgrest.dict index 672343183..2ae87ffac 100644 --- a/postgrest.dict +++ b/postgrest.dict @@ -152,6 +152,7 @@ RLS RPC RSA Saleeba +safeupdate savepoint schemas schema's