React project broken when using regex on URL query string

1. The problem I’m having:

We are hosting a very basic react project on our caddy server (fresh ubuntu 22.04 on Linode). We are trying to implement a very basic auth check to make sure a user is supposed to be on a page. We do this passing a secure-sign-in UUID in the query string of the URL. This is is mainly to prevent randos from stumbling upon the site, not for actual secure authentication.

We are trying to run regex on the secure-sign-in UUID to make sure it matches the format we send them out in.

However, in the caddyfile examples below, when we don’t implement regex and allow the secure-sign-in UUID to be * the react project loads. BUT… when we actually use regex the site will load but doesn’t actually display anything.

I feel like I have been banging my head against the wall trying to figure this out. I suspect it is a relatively quick fix but I could use some direction/help.

Thank you in advance!!!

2. Error messages and/or full log output:

3. Caddy version:

v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q=

4. How I installed and ran Caddy:

a. System environment:

Ubuntu 22.04 fresh install on Linode

b. Command:

c. Service/unit/compose file:

d. My complete Caddy config:

Functional {
        @uuid_query_param {
                query secure-sign-in=*
        rewrite @uuid_query_param /index.html

        @no_uuid {
                not query secure-sign-in=*
        respond @no_uuid "Unauthorized access" 401

        root * /var/www/portals/microsoft/build


Non-Functional {
        @uuid {
                expression `{}.matches(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[4][0-9a-fA-F]{3}-[89ABab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$")`
        handle @uuid {
                rewrite * /index.html
                root * /var/www/portals/microsoft/build
                encode gzip
               handle {
                       respond "Unauthorized" 404

5. Links to relevant resources:

Did you test that your regexp is valid? You can use and choose the Golang flavor.

FYI, you can shorten your matcher like this:

        @uuid `{}.matches(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[4][0-9a-fA-F]{3}-[89ABab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$")`

Just as a contrived example, this works (requesting ?foo=abcde returns “yes”, requesting ?foo=a returns “no”):

    @test `{}.matches(r"^a.c.e$")`
    respond @test "yes"
    respond "no"

Thanks for your reply! I tested it, and it looks like the regex is working as intended. I followed your advice with adding responses to test it, and it looks like the logic and regex are working. It seems like it is something to do with the React project, because when I substitute it with a basic html file it works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.