681 Commits

Author SHA1 Message Date
lovasoa 4874fe3c69 Revert "Allow the usage of eval from user scripts in the default Content-Security-Policy"
This reverts commit dd36a28b2d.
2025-05-25 22:13:19 +02:00
lovasoa dd36a28b2d Allow the usage of eval from user scripts in the default Content-Security-Policy 2025-05-23 01:21:50 +02:00
lovasoa 5fab89fde6 fix build warning on windows 2025-05-22 00:14:13 +02:00
lovasoa 335a0a9181 bump dependencies 2025-05-20 18:49:22 +02:00
ppom 4d98b9cf2e Remove url-encoded surrounding quotes to URL parameters (#904)
* Remove url-encoded surrounding quotes to URL parameters

Fix #879

* fix special character handling

---------

Co-authored-by: ppom <>
Co-authored-by: lovasoa <contact@ophir.dev>
2025-05-20 01:06:41 +02:00
lovasoa 04e1046018 fix alert component styles 2025-05-14 00:44:51 +02:00
lovasoa f5730354fb update sql parser
see https://github.com/apache/datafusion-sqlparser-rs/blob/main/changelog/0.56.0.md
fixes https://github.com/sqlpage/SQLPage/issues/887
2025-05-06 23:32:56 +02:00
lovasoa c00446ca21 clippy 2025-05-06 22:47:12 +02:00
lovasoa 94a56bf5b9 more memory efficient CSP templates 2025-05-06 22:47:00 +02:00
lovasoa 06292a97d6 OIDC token: implementing max age for auth cookies based on ID token expiration
Refactor claims retrieval in get_authenticated_user_info to return claims directly.
2025-05-06 22:46:07 +02:00
Gus Power 1582956ae5 Extend CSP Configuration to handle user-supplied values that can contain {NONCE} (#911)
* Extend CSP Configuration to handle user-supplied values that can contain {NONCE}

* fix RequestContext to use CSP value from AppConfig

* update documentation to describe usage

* generate nonce per request; config is a string (again); added playwright test to verify subsequent requests return a different nonce.

* fix js lint `let` -> `const`

* format

* remove some useless string copies

we are still re-parsing the csp template on every request

* implement a proper csp template struct

* parse the content-security-policy just once

* fix merge issue.

* fix docs

* fix docs

* clippy

---------

Co-authored-by: lovasoa <contact@ophir.dev>
2025-05-06 09:34:46 +02:00
Ophir LOJKINE adcbaa680b Single Sign-On via OpenID Connect (#888)
* add oidc config variables

* setup a basic middleware

* implement an async http client that uses oidc

* initialize provider_metadata in OidcService

* better error handling in oidc config

* HTTP client initialization in oidc now follows global config

* oidc: implement redirects

- Add `host` configuration option for specifying the application's web address in configuration.md and app_config.rs.
- Update docker-compose.yaml to include SQLPAGE_HOST and SQLPAGE_OIDC_ISSUER_URL environment variables.
- Enhance OIDC middleware to utilize the new `host` setting for redirect URLs and improve cookie handling in oidc.rs.

* improve local oidc configurability

* log

* Update warning message in OIDC configuration to clarify how to disable it by providing a host setting

* Update OIDC redirect logging to use info level with client ID

* Refactor unauthenticated request handling in OIDC service

- Extracted logic for handling unauthenticated requests into a separate method `handle_unauthenticated_request`.
- Updated the main request handling flow to utilize the new method for improved readability and maintainability.

* Enhance OIDC service with callback handling and token processing

- Introduced `handle_oidc_callback` method to manage OIDC callback requests.
- Added `process_oidc_callback` and `exchange_code_for_token` methods for token exchange logic.
- Updated `handle_unauthenticated_request` to check for callback URL and redirect accordingly.
- Refactored `build_redirect_response` to improve clarity in response handling.

* in handle_oidc_callback use service_request.into_response

* fmt

* Implement oidc code exchange and token storage

* validate oidc cookies

- Updated `get_sqlpage_auth_cookie` to return a result for better error handling and validation of the SQLPage auth cookie.
- Improved logging throughout the OIDC service for better traceability of requests and responses.
- Adjusted the handling of OIDC callback parameters to include context in error messages.

* OIDC callback: redirect to the auth URL on failure.

* oidc use localhost for redirect config instead of 0.0.0.0 by default

* Enhance OIDC provider metadata discovery with improved logging and error context

* maintain the initial URL during OIDC authentication

- Added state cookie handling to maintain the initial URL during OIDC authentication.
- Refactored `build_auth_url` to accept the initial URL as a parameter.
- Enhanced `process_oidc_callback` to retrieve the state from the cookie and redirect accordingly.

* implement csrf token

* update deps

* update sso examples

* nonce verification

- Improved error logging for invalid auth cookies and ID token verification.
- Introduced nonce verification logic to ensure security during OIDC authentication.
- Adjusted parameters for nonce hashing to optimize for short-lived tokens.

* Refactor OIDC logging and improve documentation

- Updated logging statements for better clarity and context.
- Refactored code for nonce verification and error handling.
- Enhanced documentation in `app_config.rs` for clarity on `https_domain` usage.

* Remove unused app_state field from OidcService struct

* Enhance OIDC client error handling and refactor HTTP request types

- Added context to OIDC client creation error handling.
- Updated HTTP request and response types for better integration with the openidconnect library.
- Introduced AwcWrapperError for improved error management in HTTP calls.

* clippy fixes

- Changed http_client from Arc to Rc in OidcService for improved memory efficiency.
- Updated related code to reflect the new ownership model for the HTTP client.

* initialize the oidc and http clients only once

- Added OidcState struct to encapsulate OIDC configuration and client.
- Refactored OidcMiddleware to utilize OidcState for improved state management.
- Updated HTTP client handling in OIDC service methods for better integration with app data.
- Enhanced logging for OIDC middleware initialization and request processing.

* functions for accessing user claims from OIDC tokens + documentation

- Updated SQLPage authentication component documentation for clarity on usage and options.
- Removed deprecated login and redirect handler scripts to streamline the SSO implementation.
- Enhanced logout functionality to properly clear session cookies and redirect users.
- Improved request handling to include OIDC claims in the request context for better user information retrieval.

* better sso troubleshooting info

* fmt

* add sso to the changelog
2025-05-05 17:59:07 +02:00
lovasoa 7d1e85f2fc fix unstable lib usage 2025-04-21 09:28:37 +02:00
lovasoa edf09c9534 Optimize memory layout by boxing large structs. Slightly reduces memory usage. 2025-04-21 01:23:59 +02:00
lovasoa 540f3d3000 fix clippy warnings 2025-04-21 00:33:31 +02:00
lovasoa c31f960c4b clippy 2025-04-20 05:42:49 +02:00
lovasoa 1a0b1d028c remove utf8 conversion 2025-03-22 18:44:58 +01:00
lovasoa 74447eaee7 hide dotfiles 2025-03-22 17:48:20 +01:00
lovasoa 757389c16b tests 2025-03-17 16:38:16 +01:00
lovasoa 2bf0a2fc9f get_preset_options 2025-03-17 15:48:30 +01:00
lovasoa 3957c59557 update markdown preset logic 2025-03-17 15:28:42 +01:00
Gus Power 2cfbe4bda6 clippy fix 2025-03-17 10:27:54 +00:00
Gus Power 1fe7687917 format and switch to use arg.value() and args.get(1) 2025-03-17 10:22:04 +00:00
Gus Power 8c7d6c7582 inline markdown::Option import 2025-03-17 10:07:05 +00:00
Gus Power 2702cbcc36 introduce MarkdownConfig trait to simplify testing; introduce allow_unsafe optional parameter to MarkdownHelper, add tests for various permutations, extend text.handlebars to pass through parameter 2025-03-13 11:15:20 +00:00
lovasoa 9fc35fbb5b update sql parser 2025-03-05 23:00:40 +01:00
lovasoa ae7f2496ec fix https://github.com/sqlpage/SQLPage/issues/839
fixed in sqlx

add a regression test

update dependencies
2025-03-05 22:27:12 +01:00
lovasoa 8b6f9eab69 add support for data url images in markdown
fixes https://github.com/sqlpage/SQLPage/discussions/803
2025-03-01 22:33:38 +01:00
lovasoa 2fce6becd3 #[allow(clippy::upper_case_acronyms)] 2025-02-27 14:03:30 +01:00
lovasoa ddf4259041 fmt 2025-02-27 14:02:59 +01:00
lovasoa befef0d7b8 Merge remote-tracking branch 'refs/remotes/origin/main' 2025-02-27 13:44:13 +01:00
lovasoa 8284501d8c escape css class names 2025-02-27 13:43:16 +01:00
Ophir LOJKINE b7b1b2123c Add markdown rendering options to the sqlpage configuration (#823)
* Add markdown rendering options to the sqlpage configuration

* fmt

* silence clippy

* revert changes to conf

* docs

* fmt
2025-02-25 19:05:39 +01:00
lovasoa ea1af2c136 cleanup 2025-02-25 18:19:23 +01:00
lovasoa 433162a9f2 error handling 2025-02-24 22:11:45 +01:00
Ophir LOJKINE 5fd1c83df1 new function: fetch_with_meta (#827)
* new function: fetch_with_meta

closes https://github.com/sqlpage/SQLPage/issues/792

* fmt

* clippy auto

* test fetch_with_meta

* fix tests

* update deps

* retry failed deps downloads

* better json serializing

* test fetch_with_meta error handling

* add logging

* fix tests



closes #792
2025-02-24 22:01:30 +01:00
Ophir LOJKINE 668a87764f fix parameter binding order (#825)
* use numbered parameters in sqlite

* implement parameter deduplication

* implement parameter re-duplication for mysql

* Improve error messages on invalid sqlpage function calls. The messages now contain actionable advice.

* simplify extract_set_variable
2025-02-22 14:13:45 +01:00
lovasoa 2aac5f3aa2 docs and tests 2025-02-17 14:31:41 +01:00
lovasoa 9804a662bd update rand 2025-02-14 23:36:28 +01:00
lovasoa 436ca17e20 update sql parser 2025-02-14 23:26:39 +01:00
lovasoa 389bad3d36 lint 2025-02-13 21:14:14 +01:00
lovasoa 3ab42fced6 new function: sqlpage.headers()
closes https://github.com/sqlpage/SQLPage/discussions/810
2025-02-13 17:33:02 +01:00
lovasoa a6a872ef88 Improve the error message
when a header component (e.g. status_code, json, cookie) is used in the wrong place (after data has already been sent to the client).
2025-02-13 14:35:01 +01:00
lovasoa 5a79514d14 make page embedding and custom layouts easier and less error prone
- The `embed` property now automatically adds the `_sqlpage_embed` parameter to the embedded page URL to render it as an embeddable fragment.
  - When an embedded page is rendered, the `shell` component is automatically replaced by a `shell-empty` component, to avoid displaying a duplicate shell and creating invalid duplicated page metadata in the response.

see https://github.com/sqlpage/SQLPage/issues/799
2025-02-10 23:04:53 +01:00
lovasoa 817fd97476 new sqlpage functions to read HTTP request body
sqlpage.request_body and sqlpage.request_body_base64

closes https://github.com/sqlpage/SQLPage/issues/316
2025-02-10 16:53:24 +01:00
lovasoa 5a7ca66c03 forbid invalid fields in sqlpage.fetch http request definitions 2025-02-10 10:18:41 +01:00
lovasoa 4c88bd7974 make the headers field in sqlpage.fetch optional
fixes https://github.com/sqlpage/SQLPage/discussions/805
2025-02-10 10:11:36 +01:00
lovasoa 828406792b fix truncated sqlpage function error traces 2025-02-10 09:44:20 +01:00
lovasoa 8a85d07e52 remove mssql-incompatible query 2025-02-03 03:29:35 +01:00
lovasoa 1086ca2347 fix warning on windows 2025-02-03 03:28:00 +01:00