Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
(function() {
    'use strict';

    // URL safety: this file only fetches a hardcoded relative API path
    // ('/auth/validate-password') — no user-supplied URLs. See url-validator.js
    // for dynamic URL validation.

    /**
     * Validate password strength via server API.
     * Single source of truth — calls PasswordValidator.validate_strength() on server.
     * @param {string} password - The password to validate
     * @param {string} csrfToken - CSRF token from the form
     * @returns {Promise<{valid: boolean, errors: string[]}>}
     */
    async function validatePasswordViaAPI(password, csrfToken) {
        // Use URLSearchParams (application/x-www-form-urlencoded) instead of
        // FormData (multipart/form-data) so the CSRF middleware can read
        // csrf_token from the body without a multipart parser.
        const body = new URLSearchParams();
        body.append('password', password);
        body.append('csrf_token', csrfToken);
        try {
            const resp = await fetch('/auth/validate-password', {
                method: 'POST',
                headers: {
                    'X-CSRFToken': csrfToken,
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body,
            });
            if (!resp.ok) {
                // CSRF expiry or server error — let server-side catch it on submit
                return { valid: true, errors: [] };
            }
            return await resp.json();
        } catch {
            // Network error — let server-side validation catch it on submit
            return { valid: true, errors: [] };
        }
    }

    window.validatePasswordViaAPI = validatePasswordViaAPI;
})();