Skip to content

Keep authentication example redirects on site - #1477

Draft
lovasoa wants to merge 1 commit into
mainfrom
codex/auth-example-safe-redirects
Draft

lovasoa wants to merge 1 commit into
mainfrom
codex/auth-example-safe-redirects

Conversation

@lovasoa

@lovasoa lovasoa commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

The CRUD authentication example used the untrusted path query parameter directly as a post-login or logout redirect. Crafted links could send users to an external site. The example now accepts local absolute and relative paths, including ./ and ../, and falls back to a local page for unsafe values.

The Hurl flow now exercises external, authority-relative, backslash, encoded, and valid relative targets. Both example READMEs document the rule.

Validation: 24 Hurl requests passed against the current locally built SQLPage binary. The Docker helper uses the older lovasoa/sqlpage:main image, which could not parse this checkout's SQL syntax.

@81reap 81reap left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docker helper uses the older lovasoa/sqlpage:main image, which could not parse this checkout's SQL syntax.

are we sure about this, the main tag has a new image from 5 days ago? how is CI passing if it uses the docker image to test? maybe a stale local image, is there a way to force repull/upgrade?

also this is the same raw $path bug, no?

https://github.com/sqlpage/SQLPage/blob/main/examples/CRUD%20-%20Authentication/www/currencies_item_dml.sql#L83

https://github.com/sqlpage/SQLPage/blob/main/examples/CRUD%20-%20Authentication/www/currencies_item_dml.sql#L94

Comment on lines +29 to +47
iif(
$path IS NOT NULL
AND length($path) > 0
AND (
(substr($path, 1, 1) = '/' AND substr($path, 2, 1) <> '/')
OR (
(substr($path, 1, 1) GLOB '[A-Za-z0-9_]'
OR substr($path, 1, 2) = './'
OR substr($path, 1, 3) = '../')
AND instr($path, ':') = 0
)
)
AND instr($path, char(92)) = 0
AND instr($path, '%') = 0
AND instr($path, char(0)) = 0
AND ($path GLOB '*[' || char(1) || '-' || char(31) || char(127) || ']*') = 0,
$path,
'/'
) AS link;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the duplicated copy in logout would be cleaner to read as a CASE statement https://www.w3schools.com/sql/sql_case.asp something like

set return_to = CASE
    WHEN $path GLOB '*[' || char(1) || '-' || char(31) || char(127) || '%\]*' THEN NULL
    WHEN instr($path, char(0)) > 0                          THEN NULL
    WHEN $path = '/' OR $path GLOB '/[^/]*'                 THEN $path
    WHEN $path GLOB './*' OR $path GLOB '../*'              THEN $path
    WHEN $path GLOB '[A-Za-z0-9_]*' AND instr($path,':') = 0 THEN $path
END;

[Asserts]
header "Location" == "/login.sql?path=/currencies_list.sql"

POST http://localhost:8080/create_session.sql?path=https%3A%2F%2Fevil.example

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing for create is not as robust as logout. we should test the same edge cases here

@lovasoa
lovasoa marked this pull request as draft September 24, 2026 19:27
@lovasoa
lovasoa force-pushed the codex/auth-example-safe-redirects branch from 21bdb18 to 73b496f Compare September 27, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants