Skip to content

Commit 82fd57d

Browse files
committed
improve official site docs
1 parent a14417d commit 82fd57d

File tree

4 files changed

+96
-6
lines changed

4 files changed

+96
-6
lines changed

examples/official-site/get started.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ select 'shell' as component,
99
'Poppins' as font;
1010

1111
SELECT 'hero' as component,
12-
'SQLPage setup' as title,
12+
'My first app' as title,
1313
'Let''s create your first SQLPage website together, step by step, from downloading SQLPage to making your site available online for everyone to browse.' as description,
1414
'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Backlit_keyboard.jpg/1024px-Backlit_keyboard.jpg' as image,
1515
'mailto:[email protected]' as link,
@@ -116,8 +116,8 @@ SELECT :Username
116116
WHERE :Username IS NOT NULL;
117117
```
118118
119-
The snippet above uses an [`INSERT INTO SELECT` SQL statement](https://www.sqlite.org/lang_insert.html) to insert a new row into the `users` table
120-
when the form is submitted.
119+
The snippet above uses an [`INSERT INTO SELECT` SQL statement](https://www.sqlite.org/lang_insert.html) to
120+
[safely](safety.sql) insert a new row into the `users` table when the form is submitted.
121121
It uses a `WHERE` clause to make sure that the `INSERT` statement is only executed when the `:Username` parameter is present.
122122
The `:Username` parameter is set to `NULL` when you initially load the page, and then SQLPage automatically sets it to the value
123123
from the text field when the user submits the form.

examples/official-site/index.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ SQLPage is a *web server* written in
7575
[rust](https://en.wikipedia.org/wiki/Rust_(programming_language))
7676
and [distributed as a single executable file](https://github.com/lovasoa/SQLpage/releases).
7777
When it receives a request with a URL ending in `.sql`, it finds the corresponding
78-
SQL file, runs it on the database,
79-
passing it information from the web request as SQL statement parameters.
78+
SQL file, runs it on the database, passing it information from the web request as SQL statement parameters
79+
[in a safe manner](safety.sql).
8080
When the database starts returning rows for the query,
8181
SQLPage maps each piece of information in the row to a parameter in the template of a pre-defined component,
8282
and streams the result back to the user''s browser.

examples/official-site/safety.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
select 'shell' as component,
2+
'SQLPage safety' as title,
3+
'shield-check-filled' as icon,
4+
'/' as link,
5+
'en-US' as lang,
6+
'SQLPage security guarantees' as description,
7+
'documentation' as menu_item,
8+
20 as font_size,
9+
'Poppins' as font;
10+
11+
select 'text' as component,
12+
'
13+
# SQLPage''s security guarantees
14+
15+
SQLPage is a tool that allows you to create a full website using only SQL queries, and render results straight from the database to the browser.
16+
Most programmers, hearing this, will immediately think of the security implications of this model.
17+
18+
This page is here to provide a list of the security guarantees that SQLPage provides.
19+
SQLPage was designed from the ground up to be usable by non-technical *data analysts* and other non-web-developers,
20+
so it provides safe defaults everywhere, so that you don''t have to worry about inadvertently
21+
exposing more data than you intended.
22+
23+
24+
## Protection against SQL injections
25+
26+
SQL injections are a common security vulnerability in traditional back-end web development,
27+
that allow an attacker to execute arbitrary SQL code on your database.
28+
29+
**SQLPage is immune to SQL injections**, because it uses [prepared statements](https://en.wikipedia.org/wiki/Prepared_statement)
30+
to pass parameters to your SQL queries.
31+
32+
When a web page starts rendering, and before processing any user inputs, all your SQL queries have already been prepared, and no
33+
new SQL code can be passed to the database. Whatever evil inputs a user might try to pass to your website,
34+
it will never be executed as SQL code on the database.
35+
36+
SQLPage **cannot** execute any other SQL code than the one you, the site author, wrote in your SQL files.
37+
38+
If you have a SQL query that looks like this:
39+
40+
```sql
41+
SELECT * FROM users WHERE userid = $id;
42+
```
43+
44+
and a user tries to pass the following value to the `id` parameter:
45+
46+
```
47+
1; DROP TABLE users;
48+
```
49+
50+
SQLPage will execute the search for the user with id `1; DROP TABLE users;` (and most likely not find any user with that id),
51+
but it *will not* execute the `DROP TABLE` statement.
52+
53+
## Protection against XSS attacks
54+
55+
XSS attacks are a common security vulnerability in traditional front-end web development,
56+
that allow an attacker to execute arbitrary JavaScript code on your users'' browsers.
57+
58+
**SQLPage is immune to XSS attacks**, because it uses an HTML-aware templating engine to render your SQL results to HTML.
59+
When you execute the following SQL code:
60+
61+
```sql
62+
SELECT ''text'' AS component, ''<script>alert("I am evil")</script>'' AS contents;
63+
```
64+
65+
it will be rendered as:
66+
67+
```html
68+
<p>
69+
&lt;script&gt;alert("I am evil")&lt;/script&gt;
70+
</p>
71+
```
72+
73+
Additionnally, SQLPage uses a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
74+
that disallows the execution of any inline JavaScript code, and only allows loading JavaScript code from trusted sources.
75+
76+
If you have some legitimate JavaScript code that you want to execute on your website, you can use the `javascript`
77+
parameter of the [`shell`](documentation.sql?component=shell#component) component to do so.
78+
79+
## Database connections
80+
81+
SQLPage uses a fixed pool of database connections, and will never open more connections than the ones you
82+
[configured](https://github.com/lovasoa/SQLpage/blob/main/configuration.md). So even under heavy load, your database
83+
connection limit should never be saturated by SQLPage.
84+
85+
And SQLPage will accept any restriction you put on the database user you use to connect to your database, so you can
86+
create a specific user for SQLPage that only has access to the specific tables you will use in your application.
87+
88+
If your entire application is read-only, you can even create a user that only has the `SELECT` privilege on your database,
89+
90+
' as contents_md;

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ For instance, if you were creating a form to manage a list of users, you could c
250250
- a file named `users.sql` that would contain a list of users and a form to create a new user,
251251
- a file named `create_user.sql` that would insert the new user in the database, and then redirect to `users.sql`.
252252
253-
`create_user.sql` could contain a sql statement like
253+
`create_user.sql` could contain the following sql statement to [safely](safety.sql) insert the new user in the database:
254254
255255
```sql
256256
INSERT INTO users(name) VALUES(:username)

0 commit comments

Comments
 (0)