Summary
A broken access control issue in Gogs causes the attachments download endpoint to serve raw files without checking whether the requester can view the related issue, comment, release, or repository.
Under typical configurations, this can allow unauthorized users, including unauthenticated ones in some setups, to download attachments from private repositories when they know or can guess the attachment UUID.
Affected context
The vulnerability occurs in Gogs instances that expose the /attachments/:uuid endpoint and rely on repository or issue-level permissions to protect attachment content.
It is most relevant when private repositories or restricted issues/comments/releases store sensitive files as attachments.
In environments configured with REQUIRE_SIGNIN_VIEW = false, unauthenticated users may be able to access attachments if they possess a valid UUID, but even with sign-in required, missing checks on the attachment's parent resource can still lead to unauthorized access.
Exploit preconditions
- Attack surface: HTTP GET requests to the
/attachments/:uuidendpoint on a Gogs server. - Required access: Ability to reach the Gogs web interface; in some configurations, no authentication is needed.
- Trigger point: Supplying a valid UUID for an attachment whose parent issue/comment/release or repository should not be visible to the requester.
- Why exploitation is possible: The endpoint returns the raw attachment file without enforcing permission checks against the associated resource or repository, violating object-level access control expectations.
Why this happens
The bug stems from treating attachment resources as independently accessible objects without re-validating access against their owning entities.
Instead of enforcing repository or issue-level authorization at the time of file download, the implementation trusts the presence of a UUID alone.
This aligns with CWE-639: Authorization Bypass Through User-Controlled Key and CWE-862: Missing Authorization, where user-supplied identifiers reference protected objects without corresponding permission checks.
Potential impact
- Unauthorized users may download attachments from private repositories.
- Sensitive documents, logs, or artifacts stored as attachments could be exposed.
- Confidential project information and intellectual property can be leaked.
- Compliance violations may occur if regulated data is stored in attachments.
General mitigation guidance
Mitigation generally involves enforcing object-level access control whenever direct references are used.
Secure patterns include:
- Validating the requester's permissions against the attachment's parent repository or issue before serving the file.
- Centralizing authorization logic so that all resource-specific endpoints delegate permission checks to shared access-control mechanisms.
- Avoiding endpoints that serve data purely based on opaque identifiers without correlating them to the user's effective privileges.
- Reducing the sensitivity of data stored in attachments or segregating highly sensitive files behind stricter access controls.
How teams detect issues like this
Effective detection often combines code-centric and configuration-focused approaches:
- Static analysis and manual review looking for endpoints that retrieve objects by ID or UUID without invoking permission checks on the associated parent resource.
- Auditing handler functions for download or export operations to ensure they incorporate role and repository visibility checks.
- Implementing security tests that attempt to access attachments from private repositories using accounts with no repository access or with no authentication.
- Using automated security scanning tools and policies that flag any direct object reference lacking an authorization call path.

