Skip to content

feat(security): Suppport for whitelisting and logout on 401#66

Merged
nfebe merged 3 commits into
mainfrom
fix/security-session-and-whitelist
Jun 6, 2026
Merged

feat(security): Suppport for whitelisting and logout on 401#66
nfebe merged 3 commits into
mainfrom
fix/security-session-and-whitelist

Conversation

@nfebe

@nfebe nfebe commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

No description provided.

nfebe added 2 commits June 6, 2026 14:53
Only auth endpoints used to trigger a logout on 401. A dashboard tab
left open past session expiry kept polling with a dead token, and the
resulting stream of failed requests looked like a brute-force attack
to the security module, which repeatedly auto-blocked the operator's
IP. The first 401 outside the login and setup pages now clears the
session and returns to the login page, which also stops all pollers.
…shboard

The security whitelist could only be edited through the API and the
detection thresholds only through the config file. The Security view
now lists whitelisted IPs, networks, and paths with add and remove
controls, and the settings tab exposes the detection window, per-window
limits, and auto-block duration. Threshold changes persist and apply to
the running detector immediately.
@sourceant

sourceant Bot commented Jun 6, 2026

Copy link
Copy Markdown

Code Review Summary

This PR adds comprehensive support for security whitelisting (IP, CIDR, and Paths) and dynamic configuration of detection thresholds. It also improves session management by handling 401 Unauthorized responses correctly in the API interceptor.

🚀 Key Improvements

  • Implemented whitelisting management UI and store logic.
  • Added dynamic configuration for security thresholds (Rate limits, 404 thresholds, etc.).
  • Improved 401 error handling to redirect users to login while avoiding loops on the login page itself.
  • Centralized configuration management via configApi.

💡 Minor Suggestions

  • Input trimming for whitelist values.
  • Prevention of mouse-wheel changes on numeric inputs to avoid accidental configuration shifts.

@sourceant sourceant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review complete. See the overview comment for a summary.

const saveThresholds = async () => {
savingThresholds.value = true;
try {
const changed = thresholdFields.filter((f) => thresholds[f.key] !== loadedThresholds.value[f.key]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sequential await calls for saving thresholds can be slow if there are many changes. While the current list is small, using Promise.all would improve performance by executing these independent network requests in parallel.

Suggested change
const changed = thresholdFields.filter((f) => thresholds[f.key] !== loadedThresholds.value[f.key]);
const changed = thresholdFields.filter((f) => thresholds[f.key] !== loadedThresholds.value[f.key]);
await Promise.all(changed.map(field => configApi.set(`security.${field.key}`, thresholds[field.key])));
for (const field of changed) {
loadedThresholds.value[field.key] = thresholds[field.key];
}

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 6, 2026

Copy link
Copy Markdown

Deploying flatrun-ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: a9910ee
Status: ✅  Deploy successful!
Preview URL: https://c0900e9a.flatrun-ui.pages.dev
Branch Preview URL: https://fix-security-session-and-whi.flatrun-ui.pages.dev

View logs

@sourceant sourceant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review complete. See the overview comment for a summary.

Comment thread src/services/api.ts
const failedURL: string = error.config?.url || "";
const isSessionEndpoint = /\/auth\/|\/users\/me(\b|\/)/.test(failedURL);
if (isSessionEndpoint) {
const isLoginAttempt = failedURL.includes("/auth/login");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The logic to prevent redirecting on the login page could be simplified. Checking window.location.pathname for the exact match or using a whitelist of non-auth paths is safer than partial string matches which might catch sub-routes unexpectedly.

Suggested change
const isLoginAttempt = failedURL.includes("/auth/login");
const isLoginAttempt = failedURL.includes("/auth/login");
const onAuthPage = ["/login", "/setup"].some(path => window.location.pathname.startsWith(path));
if (!isLoginAttempt && !onAuthPage) {

};

const handleAddWhitelistEntry = async () => {
if (!whitelistForm.value) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's best practice to trim the whitelist value to prevent accidental whitespace leading to invalid IP or path entries which might not match correctly on the server.

Suggested change
if (!whitelistForm.value) return;
const val = whitelistForm.value.trim();
if (!val) return;
addingWhitelistEntry.value = true;
try {
await securityStore.addWhitelistEntry({
value: val,

@nfebe nfebe merged commit 5768129 into main Jun 6, 2026
5 checks passed
@nfebe nfebe deleted the fix/security-session-and-whitelist branch June 6, 2026 15:21
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.

1 participant