Skip to content

Commit 94f9988

Browse files
authored
Format protected and public paths with site prefix (#1204)
* Format protected and public paths with site prefix Update protected and public paths to include site prefix. * Fix formatting of paths in OIDC module * Validate that paths start with '/' in config * Refactor path handling for OIDC configuration * Update OIDC paths configuration details * code fix+clippy hints+formatting
1 parent d30eec8 commit 94f9988

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Here are the available configuration options and their default values:
2525
| `configuration_directory` | `./sqlpage/` | The directory where the `sqlpage.json` file is located. This is used to find the path to [`templates/`](https://sql-page.com/custom_components.sql), [`migrations/`](https://sql-page.com/your-first-sql-website/migrations.sql), and `on_connect.sql`. Obviously, this configuration parameter can be set only through environment variables, not through the `sqlpage.json` file itself in order to find the `sqlpage.json` file. Be careful not to use a path that is accessible from the public WEB_ROOT |
2626
| `allow_exec` | false | Allow usage of the `sqlpage.exec` function. Do this only if all users with write access to sqlpage query files and to the optional `sqlpage_files` table on the database are trusted. |
2727
| `max_uploaded_file_size` | 5242880 | Maximum size of forms and uploaded files in bytes. Defaults to 5 MiB. |
28-
| `oidc_protected_paths` | `["/"]` | A list of URL prefixes that should be protected by OIDC authentication. By default, all paths are protected (`["/"]`). If you want to make some pages public, you can restrict authentication to a sub-path, for instance `["/admin", "/users/settings"]`. |
29-
| `oidc_public_paths` | `[]` | A list of URL prefixes that should be publicly available. By default, no paths are publicly accessible (`[]`). If you want to make some pages public, you can bypass authentication for a sub-path, for instance `["/public/", "/assets/"]`. Keep in mind that without the closing backslashes, that any directory or file starting with `public` or `assets` will be publicly available. This will also overwrite any protected path restriction. If you have a private path `/private` and you define the public path `/private/public/` everything in `/private/public/` will be publicly accessible, while everything else in private will still need authentication.
28+
| `oidc_protected_paths` | `["/"]` | A list of URL prefixes that should be protected by OIDC authentication. By default, all paths are protected (`["/"]`). If you want to make some pages public, you can restrict authentication to a sub-path, for instance `["/admin", "/users/settings"]`. All paths must start with a "/" and will be prepended by `site_prefix` if defined.|
29+
| `oidc_public_paths` | `[]` | A list of URL prefixes that should be publicly available. By default, no paths are publicly accessible (`[]`). If you want to make some pages public, you can bypass authentication for a sub-path, for instance `["/public/", "/assets/"]`. Keep in mind that without the closing backslashes, that any directory or file starting with `public` or `assets` will be publicly available. This will also overwrite any protected path restriction. If you have a private path `/private` and you define the public path `/private/public/` everything in `/private/public/` will be publicly accessible, while everything else in private will still need authentication. All paths must start with a "/" and will be prepended by `site_prefix` if defined.
3030
| `oidc_issuer_url` | | The base URL of the [OpenID Connect provider](#openid-connect-oidc-authentication). Required for enabling Single Sign-On. |
3131
| `oidc_client_id` | sqlpage | The ID that identifies your SQLPage application to the OIDC provider. You get this when registering your app with the provider. |
3232
| `oidc_client_secret` | | The secret key for your SQLPage application. Keep this confidential as it allows your app to authenticate with the OIDC provider. |

src/app_config.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ impl AppConfig {
131131
}
132132
}
133133
anyhow::ensure!(self.max_pending_rows > 0, "max_pending_rows cannot be null");
134+
135+
for path in &self.oidc_protected_paths {
136+
if !path.starts_with('/') {
137+
return Err(anyhow::anyhow!(
138+
"All protected paths must start with '/', but found: '{path}'"
139+
));
140+
}
141+
}
142+
143+
for path in &self.oidc_public_paths {
144+
if !path.starts_with('/') {
145+
return Err(anyhow::anyhow!(
146+
"All public paths must start with '/', but found: '{path}'"
147+
));
148+
}
149+
}
150+
134151
Ok(())
135152
}
136153
}

src/webserver/oidc.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,25 @@ impl TryFrom<&AppConfig> for OidcConfig {
9292
let client_secret = config.oidc_client_secret.as_ref().ok_or(Some(
9393
"The \"oidc_client_secret\" setting is required to authenticate with the OIDC provider",
9494
))?;
95-
let protected_paths: Vec<String> = config.oidc_protected_paths.clone();
96-
let public_paths: Vec<String> = config.oidc_public_paths.clone();
9795

9896
let app_host = get_app_host(config);
9997

10098
let site_prefix_trimmed = config.site_prefix.trim_end_matches('/');
10199
let redirect_uri = format!("{site_prefix_trimmed}{SQLPAGE_REDIRECT_URI}");
102100
let logout_uri = format!("{site_prefix_trimmed}{SQLPAGE_LOGOUT_URI}");
103101

102+
let protected_paths: Vec<String> = config
103+
.oidc_protected_paths
104+
.iter()
105+
.map(|path| format!("{site_prefix_trimmed}{path}"))
106+
.collect();
107+
108+
let public_paths: Vec<String> = config
109+
.oidc_public_paths
110+
.iter()
111+
.map(|path| format!("{site_prefix_trimmed}{path}"))
112+
.collect();
113+
104114
Ok(Self {
105115
issuer_url: issuer_url.clone(),
106116
client_id: config.oidc_client_id.clone(),

0 commit comments

Comments
 (0)