Skip to content

Commit befef0d

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 8284501 + d5b6050 commit befef0d

File tree

7 files changed

+74
-20
lines changed

7 files changed

+74
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# CHANGELOG.md
22

3-
## unreleased
3+
## 0.34.0 (unreleased)
4+
45
- `delete_link` in the list component now submits a POST request, instead of being a simple link.
56
- This avoids accidental deletion by bots following links, and is more in line with HTTP semantics.
67
- In the table component, the `_col_` prefix is now added to column names in CSS classes. This avoids conflicts with other CSS classes that might be used in the page.
78
- fixes https://github.com/sqlpage/SQLPage/issues/830
89
- This is a breaking change for custom CSS rules that target table columns by their name.
910
- Before: `.my_column { ... }`
1011
- After: `._col_my_column { ... }`
12+
- New configuration options:
13+
- `markdown_allow_dangerous_html`: allow the usage of html in markdown (default: false)
14+
- `markdown_allow_dangerous_protocol`: allow the usage of custom protocols in markdown (default: false)
15+
- see [configuration.md](./configuration.md) for more details.
1116

1217
## 0.33.1 (2025-02-25)
1318

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlpage"
3-
version = "0.33.1"
3+
version = "0.34.0"
44
edition = "2021"
55
description = "Build data user interfaces entirely in SQL. A web server that takes .sql files and formats the query result using pre-made configurable professional-looking components."
66
keywords = ["web", "sql", "framework"]

configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Here are the available configuration options and their default values:
3434
| `content_security_policy` | `script-src 'self' 'nonce-XXX` | The [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) to set in the HTTP headers. If you get CSP errors in the browser console, you can set this to the empty string to disable CSP. |
3535
| `system_root_ca_certificates` | false | Whether to use the system root CA certificates to validate SSL certificates when making http requests with `sqlpage.fetch`. If set to false, SQLPage will use its own set of root CA certificates. If the `SSL_CERT_FILE` or `SSL_CERT_DIR` environment variables are set, they will be used instead of the system root CA certificates. |
3636
| `max_recursion_depth` | 10 | Maximum depth of recursion allowed in the `run_sql` function. Maximum value is 255. |
37+
| `markdown_allow_dangerous_html` | false | Whether to allow raw HTML in markdown content. Only enable this if the markdown content is fully trusted (not user generated). |
38+
| `markdown_allow_dangerous_protocol` | false | Whether to allow dangerous protocols (like javascript:) in markdown links. Only enable this if the markdown content is fully trusted (not user generated). |
3739

3840
Multiple configuration file formats are supported:
3941
you can use a [`.json5`](https://json5.org/) file, a [`.toml`](https://toml.io/) file, or a [`.yaml`](https://en.wikipedia.org/wiki/YAML#Syntax) file.

examples/official-site/sqlpage/migrations/10_map.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ VALUES
8585
TRUE,
8686
TRUE
8787
),
88+
(
89+
'map',
90+
'height',
91+
'Height of the map, in pixels. Default to 350px',
92+
'INTEGER',
93+
TRUE,
94+
TRUE
95+
),
8896
(
8997
'map',
9098
'latitude',
@@ -246,4 +254,4 @@ or abstract 2D data visualizations.
246254
}
247255
]'
248256
)
249-
);
257+
);

src/app_config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub fn load_from_env() -> anyhow::Result<AppConfig> {
143143
}
144144

145145
#[derive(Debug, Deserialize, PartialEq, Clone)]
146+
#[allow(clippy::struct_excessive_bools)]
146147
pub struct AppConfig {
147148
#[serde(default = "default_database_url")]
148149
pub database_url: String,
@@ -248,6 +249,12 @@ pub struct AppConfig {
248249
/// Maximum depth of recursion allowed in the `run_sql` function.
249250
#[serde(default = "default_max_recursion_depth")]
250251
pub max_recursion_depth: u8,
252+
253+
#[serde(default = "default_markdown_allow_dangerous_html")]
254+
pub markdown_allow_dangerous_html: bool,
255+
256+
#[serde(default = "default_markdown_allow_dangerous_protocol")]
257+
pub markdown_allow_dangerous_protocol: bool,
251258
}
252259

253260
impl AppConfig {
@@ -506,6 +513,14 @@ fn default_max_recursion_depth() -> u8 {
506513
10
507514
}
508515

516+
fn default_markdown_allow_dangerous_html() -> bool {
517+
false
518+
}
519+
520+
fn default_markdown_allow_dangerous_protocol() -> bool {
521+
false
522+
}
523+
509524
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone, Copy, Eq, Default)]
510525
#[serde(rename_all = "lowercase")]
511526
pub enum DevOrProd {

src/template_helpers.rs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) {
6666

6767
// icon helper: generate an image with the specified icon
6868
h.register_helper("icon_img", Box::new(IconImgHelper(site_prefix)));
69-
register_helper(h, "markdown", markdown_helper as EH);
69+
register_helper(h, "markdown", MarkdownHelper::new(config));
7070
register_helper(h, "buildinfo", buildinfo_helper as EH);
7171
register_helper(h, "typeof", typeof_helper as H);
7272
register_helper(h, "rfc2822_date", rfc2822_date_helper as EH);
@@ -250,21 +250,45 @@ fn typeof_helper(v: &JsonValue) -> JsonValue {
250250
.into()
251251
}
252252

253-
fn markdown_helper(x: &JsonValue) -> anyhow::Result<JsonValue> {
254-
let as_str = match x {
255-
JsonValue::String(s) => Cow::Borrowed(s),
256-
JsonValue::Array(arr) => Cow::Owned(
257-
arr.iter()
258-
.map(|v| v.as_str().unwrap_or_default())
259-
.collect::<Vec<_>>()
260-
.join("\n"),
261-
),
262-
JsonValue::Null => Cow::Owned(String::new()),
263-
other => Cow::Owned(other.to_string()),
264-
};
265-
markdown::to_html_with_options(&as_str, &markdown::Options::gfm())
266-
.map(JsonValue::String)
267-
.map_err(|e| anyhow::anyhow!("markdown error: {e}"))
253+
/// Helper to render markdown with configurable options
254+
struct MarkdownHelper {
255+
allow_dangerous_html: bool,
256+
allow_dangerous_protocol: bool,
257+
}
258+
259+
impl MarkdownHelper {
260+
fn new(config: &AppConfig) -> Self {
261+
Self {
262+
allow_dangerous_html: config.markdown_allow_dangerous_html,
263+
allow_dangerous_protocol: config.markdown_allow_dangerous_protocol,
264+
}
265+
}
266+
}
267+
268+
impl CanHelp for MarkdownHelper {
269+
fn call(&self, args: &[PathAndJson]) -> Result<JsonValue, String> {
270+
let as_str = match args {
271+
[v] => v.value(),
272+
_ => return Err("expected one argument".to_string()),
273+
};
274+
let as_str = match as_str {
275+
JsonValue::String(s) => Cow::Borrowed(s),
276+
JsonValue::Array(arr) => Cow::Owned(
277+
arr.iter()
278+
.map(|v| v.as_str().unwrap_or_default())
279+
.collect::<Vec<_>>()
280+
.join("\n"),
281+
),
282+
JsonValue::Null => Cow::Owned(String::new()),
283+
other => Cow::Owned(other.to_string()),
284+
};
285+
let mut options = markdown::Options::gfm();
286+
options.compile.allow_dangerous_html = self.allow_dangerous_html;
287+
options.compile.allow_dangerous_protocol = self.allow_dangerous_protocol;
288+
markdown::to_html_with_options(&as_str, &options)
289+
.map(JsonValue::String)
290+
.map_err(|e| e.to_string())
291+
}
268292
}
269293

270294
fn buildinfo_helper(x: &JsonValue) -> anyhow::Result<JsonValue> {

0 commit comments

Comments
 (0)