Summary
SiYuan contains an authentication rate-limiting weakness in the CheckAuth() middleware, allowing unlimited automated attempts against the workspace access code through HTTP Basic Authentication. A remote unauthenticated attacker who successfully guesses the code may obtain administrator-level access to the kernel and its protected API surface.
Affected context
The weakness occurs in SiYuan deployments that protect the /api/* interface with HTTP Basic Authentication using the workspace access code. The Basic Authentication path does not share the CAPTCHA, lockout, or failure-counter controls used by the cookie/session login flow, and the credential comparison also does not provide constant-time behavior.
Exploit preconditions
- Attack surface: Network-accessible SiYuan HTTP API endpoints
- Required access: No prior authentication is required
- Trigger point: Repeated HTTP Basic Authentication requests handled by
CheckAuth() - Required condition: The protected interface must be reachable and use the workspace access code for Basic Authentication
- Why exploitation is possible: The Basic Authentication branch neither enforces the existing lockout gate nor increments the failure counter, permitting unlimited automated guesses
Why this happens
The vulnerability results from inconsistent enforcement of authentication controls across login mechanisms. The HTTP Basic Authentication branch accepts the workspace access code but bypasses the CAPTCHA and failure-tracking logic applied to the session-based path, creating an unrestricted password-guessing channel. This maps to CWE-307: Improper Restriction of Excessive Authentication Attempts. The non-constant-time string comparison is a secondary weakness that may expose timing information and further reduces authentication robustness.
Potential impact
- An attacker may recover the workspace access code through automated guessing
- Successful authentication could grant full RoleAdministrator access to the kernel
- Attackers could access, modify, or delete protected API-managed data
- An attacker could alter application configuration or operational state
- Compromise could enable further attacks against connected services or users
General mitigation guidance
Mitigation generally focuses on applying uniform authentication protections to every credential validation path.
Common defensive patterns include:
- Enforcing rate limits, lockouts, progressive delays, and abuse detection for HTTP Basic Authentication as well as session login
- Maintaining a shared failure counter and CAPTCHA or equivalent challenge policy across authentication mechanisms
- Using constant-time credential comparisons where practical
- Replacing shared access codes with individually attributable credentials or stronger authentication factors
- Restricting administrative API exposure through network segmentation, reverse-proxy policy, and least privilege
- Avoiding direct internet exposure of administrative interfaces unless strong compensating controls are present
How teams detect issues like this
Organizations commonly detect this weakness through:
- Static analysis and code review checks that compare authentication branches for equivalent rate-limiting behavior
- Review signals showing credential validation without failure counters, lockout checks, or progressive delay
- Tests that issue repeated invalid Basic Authentication requests and verify that enforcement activates
- Monitoring for high-volume authentication failures, repeated requests from one source, and distributed guessing patterns
- Policy enforcement requiring administrative endpoints to use centralized authentication and abuse-prevention middleware
- Automated security review tools that flag direct credential comparisons and authentication paths lacking throttling controls

