Skip to content

feat: add TINYAUTH_AUTH_SINGLECOOKIEDOMAIN option (and fix release workflow)#710

Open
jacekkow wants to merge 1 commit intosteveiliop56:mainfrom
jacekkow:single-cookie-domain
Open

feat: add TINYAUTH_AUTH_SINGLECOOKIEDOMAIN option (and fix release workflow)#710
jacekkow wants to merge 1 commit intosteveiliop56:mainfrom
jacekkow:single-cookie-domain

Conversation

@jacekkow
Copy link
Contributor

@jacekkow jacekkow commented Mar 12, 2026

It allows to set-up Tinyauth on top-level domain or to have it as a standalone OIDC server, without transparent authentication for apps in subdomains.

Additionally fix issue in release workflow where metadata (VERSION, COMMIT_HASH, BUILD_TIMESTAMP) is fetched from nightly tag rather than from the relevant v... tag.

Summary by CodeRabbit

  • New Features
    • Added standalone configuration option for authentication settings, enabling alternative cookie domain handling behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9669f37d-c76e-4dfe-bc1f-a36decae2e47

📥 Commits

Reviewing files that changed from the base of the PR and between 6465057 and 1848a7a.

📒 Files selected for processing (3)
  • internal/bootstrap/app_bootstrap.go
  • internal/config/config.go
  • internal/utils/app_utils.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/utils/app_utils.go
  • internal/config/config.go
  • internal/bootstrap/app_bootstrap.go

📝 Walkthrough

Walkthrough

The changes introduce a standalone authentication mode by adding a configuration option and implementing a strategy pattern for cookie domain resolution. When enabled, the system uses simplified hostname extraction instead of default domain validation, logging that proxied app automatic authentication will not work.

Changes

Cohort / File(s) Summary
Configuration
internal/config/config.go
Added Standalone bool field to AuthConfig struct with YAML tag to enable standalone authentication mode.
Utility Functions
internal/utils/app_utils.go
Introduced GetStandaloneCookieDomain() function that extracts hostname directly from URL without IP rejection or suffix validation checks.
Bootstrap Logic
internal/bootstrap/app_bootstrap.go
Refactored cookie domain resolution to use a runtime-selected resolver function; switches from default GetCookieDomain to GetStandaloneCookieDomain when Auth.Standalone is enabled, with info log notification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • steveiliop56

Poem

🐰 A hop through the config, standalone mode set,
Cookie domains resolved without regret,
Strategy pattern selected with grace,
Hostname extraction in its proper place! 🍪

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title partially covers the changeset but is incomplete and somewhat misleading. It mentions 'SINGLECOOKIEDOMAIN' as the feature name, but the actual implementation uses 'Standalone' mode with 'GetStandaloneCookieDomain'. Additionally, the title references a release workflow fix as a secondary concern, but the PR context indicates this fix was separated into PR #725. Consider revising the title to accurately reflect the primary feature as 'add standalone auth mode' or similar, and either remove the release workflow reference (since it was separated) or clarify the scope with better naming alignment to the actual implementation.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/utils/app_utils.go (1)

46-53: Consider validating empty hostname edge case.

Unlike GetCookieDomain, this function doesn't validate for IP addresses or empty hostnames. While the relaxed validation may be intentional for single-domain mode, url.Parse can return an empty hostname for malformed URLs (e.g., "not-a-url"), which would silently return an empty string instead of an error.

💡 Optional: Add minimal validation
 func GetCookieSingleDomain(u string) (string, error) {
 	parsed, err := url.Parse(u)
 	if err != nil {
 		return "", err
 	}
 
+	hostname := parsed.Hostname()
+	if hostname == "" {
+		return "", errors.New("invalid URL: empty hostname")
+	}
+
-	return parsed.Hostname(), nil
+	return hostname, nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/utils/app_utils.go` around lines 46 - 53, GetCookieSingleDomain
currently returns parsed.Hostname() even when url.Parse yields an empty hostname
(e.g., for malformed inputs); update GetCookieSingleDomain to validate the
parsed.Hostname() result after calling url.Parse and return a descriptive error
if the hostname is empty (or otherwise invalid), so callers receive an error
instead of an empty string; reference the GetCookieSingleDomain function, the
url.Parse call and parsed.Hostname() usage when implementing this check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/utils/app_utils.go`:
- Around line 46-53: GetCookieSingleDomain currently returns parsed.Hostname()
even when url.Parse yields an empty hostname (e.g., for malformed inputs);
update GetCookieSingleDomain to validate the parsed.Hostname() result after
calling url.Parse and return a descriptive error if the hostname is empty (or
otherwise invalid), so callers receive an error instead of an empty string;
reference the GetCookieSingleDomain function, the url.Parse call and
parsed.Hostname() usage when implementing this check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c33fc343-de8e-419c-a237-26836edd6bc4

📥 Commits

Reviewing files that changed from the base of the PR and between 03f13ef and 6465057.

📒 Files selected for processing (4)
  • .github/workflows/release.yml
  • internal/bootstrap/app_bootstrap.go
  • internal/config/config.go
  • internal/utils/app_utils.go
💤 Files with no reviewable changes (1)
  • .github/workflows/release.yml

@steveiliop56
Copy link
Owner

#724 related

@jacekkow I believe the correct approach would be to automatically detect if we are running on a non-subdomain app URL. On start-up check what strings.Split returns. If it's 2 then we are running on the root, so we show a warning that cookies will be set for .<root> and continue as normal. If it's more than 2 we are running on a subdomain so we do the regular checks for the PSL and stuff.

@jacekkow
Copy link
Contributor Author

@steveiliop56 - that is not my use case. I want to use this app as a standalone component (auth server). I do not want it to set cookies for any other domain (esp. wildcard ones). Secured applications use OIDC and are at completely different URLs.

@steveiliop56
Copy link
Owner

@jacekkow that's fine, it will not set cookies if you don't use the authentication feature. The idea is to just automatically handle root domains instead of needing another config option. Your pull request basically does this. Are you interested in implementing said feature or should I do it?

@jacekkow
Copy link
Contributor Author

it will not set cookies if you don't use the authentication feature

OIDC login does set cookies.

The idea is to just automatically handle root domains instead of needing another config option.

My instance of Tinyauth is not hosted on root domain!

So unless you've missed something my use case is different and requires a different solution than an algorithm from your first comment (#710 (comment)).

@steveiliop56
Copy link
Owner

OIDC login does set cookies.

My brain was not thinking when I wrote this.

..for the rest..

Yes you are correct again, I thought your instance was on the root. Anyway in that case I guess we could have such option. But maybe under a different name? SINGLEDOMAIN is a bit confusing imo. Maybe something like TINYAUTH_AUTH_COOKIEOIDCONLY?

@jacekkow
Copy link
Contributor Author

@steveiliop56 Sure - naming can be changed.

What I also considered is having an option to just set arbitrary "cookie domain" (TINYAUTH_AUTH_COOKIEDOMAIN maybe) - and if it is not set default to the algorithm without any modifications. If wrong value is set, it's on the user :)

What would you prefer? Renaming "my option" to TINYAUTH_AUTH_COOKIEOIDCONLY (or maybe TINYAUTH_AUTH_STANDALONE?) or an option to set cookie domain?

@steveiliop56
Copy link
Owner

I think the standalone idea is nice, let's change it to that. As for a cookie domain option, I think it's better to avoid adding it because it can and probably will cause confusion.

Also maybe we should add a small info log saying that authentication will not work for proxied apps with this option enabled (again to avoid future issues).

Small note: This pull request is "queued" for v5.1.0 which will come later. I am focusing on fixing some issues in a patch release and then we can start adding new features.

@jacekkow
Copy link
Contributor Author

jacekkow commented Mar 19, 2026

@steveiliop56 Sure, no problem, I can work with a fork for now. BTW - would you like to have commit 6465057 submitted as a separate PR for the fix release?

@steveiliop56
Copy link
Owner

Was planning to fix this with #715, I noticed it there too. But yeah feel free to create a pull request - please check if there is any nightly leftover anywhere else -.

@jacekkow
Copy link
Contributor Author

Haven't found any more of those. PR: #725

@jacekkow jacekkow force-pushed the single-cookie-domain branch from 6465057 to f66ddf9 Compare March 20, 2026 15:21
Allows to use Tinyauth on top-level domain only, but forbids
automatic cross-app authentication using Traefik or Nginx.
@jacekkow jacekkow force-pushed the single-cookie-domain branch from f66ddf9 to 1848a7a Compare March 20, 2026 15:21
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.81%. Comparing base (d71a8e0) to head (1848a7a).

Files with missing lines Patch % Lines
internal/bootstrap/app_bootstrap.go 0.00% 5 Missing ⚠️
internal/utils/app_utils.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #710      +/-   ##
==========================================
- Coverage   16.85%   16.81%   -0.04%     
==========================================
  Files          50       50              
  Lines        3820     3829       +9     
==========================================
  Hits          644      644              
- Misses       3112     3121       +9     
  Partials       64       64              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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