forgejo/.deadcode-out
Mathieu Fenniak 48da8f9888 feat: implement repo-specific access tokens broadly for universal API permission checks (#11437)
Repository-specific personal access tokens will allow a user's access tokens to be restricted to accessing zero-or-more specific repositories.  Currently they can be configured as "All", or "Public only", and this project will add a third configuration option allowing specific repositories.

This PR is part of a series (#11311), and builds on the infrastructure work in #11434.  In this PR, repository-specific access tokens are implemented on the universal permission checks performed by the API middleware, affecting ~182 API endpoints that perform permission checks based upon repositories referenced in their API path (eg. `/v1/api/repos/{owner}/{repo}/...`).

**Breaking change:** API access with a public-only access token would previously return a `403 Forbidden` error when attempting to access a private repository where the repository is on the API path.  As part of incorporating the public-only logic into the centralized permission check, these APIs will now return `404 Not Found` instead, consistent with how repository-specific access tokens, and other permissions checks, are implemented in order to reduce the risk of data probing through error messages.

For larger context on the usage and future incoming work, the description of #11311 can be referenced.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests for Go changes

(can be removed for JavaScript changes)

- I added test coverage for Go changes...
  - [ ] in their respective `*_test.go` for unit tests.
  - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I ran...
  - [x] `make pr-go` before pushing

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
    - As there is no end-user accessibility to create repo-specific access tokens, this functionality will not be accessible to end-users yet.  But the breaking change in error APIs for public-only access tokens will be visible to end-users.
- [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Breaking features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/11437): <!--number 11437 --><!--line 0 --><!--description aW1wbGVtZW50IHJlcG8tc3BlY2lmaWMgYWNjZXNzIHRva2VucyBicm9hZGx5IGZvciB1bml2ZXJzYWwgQVBJIHBlcm1pc3Npb24gY2hlY2tzLiAgKipCcmVha2luZzoqKiBBUEkgYWNjZXNzIHdpdGggYSBwdWJsaWMtb25seSBhY2Nlc3MgdG9rZW4gd291bGQgcHJldmlvdXNseSByZXR1cm4gYSBgNDAzIEZvcmJpZGRlbmAgZXJyb3Igd2hlbiBhdHRlbXB0aW5nIHRvIGFjY2VzcyBhIHByaXZhdGUgcmVwb3NpdG9yeSB3aGVyZSB0aGUgcmVwb3NpdG9yeSBpcyBvbiB0aGUgQVBJIHBhdGguICBBcyBwYXJ0IG9mIGluY29ycG9yYXRpbmcgdGhlIHB1YmxpYy1vbmx5IGxvZ2ljIGludG8gdGhlIGNlbnRyYWxpemVkIHBlcm1pc3Npb24gY2hlY2ssIHRoZXNlIEFQSXMgd2lsbCBub3cgcmV0dXJuIGA0MDQgTm90IEZvdW5kYCBpbnN0ZWFkLCBjb25zaXN0ZW50IHdpdGggaG93IG1vc3QgcGVybWlzc2lvbiBjaGVja3MgYXJlIGltcGxlbWVudGVkIGluIG9yZGVyIHRvIHJlZHVjZSB0aGUgcmlzayBvZiBkYXRhIHByb2JpbmcgdGhyb3VnaCBlcnJvciBtZXNzYWdlcy4=-->implement repo-specific access tokens broadly for universal API permission checks.  **Breaking:** API access with a public-only access token would previously return a `403 Forbidden` error when attempting to access a private repository where the repository is on the API path.  As part of incorporating the public-only logic into the centralized permission check, these APIs will now return `404 Not Found` instead, consistent with how most permission checks are implemented in order to reduce the risk of data probing through error messages.<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11437
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2026-02-28 19:47:06 +01:00

249 lines
4.2 KiB
Text

forgejo.org/cmd
NoMainListener
forgejo.org/cmd/forgejo
ContextSetNoInit
ContextSetNoExit
ContextSetStderr
ContextGetStderr
ContextSetStdout
ContextSetStdin
forgejo.org/models
IsErrSHANotFound
IsErrMergeDivergingFastForwardOnly
forgejo.org/models/auth
WebAuthnCredentials
forgejo.org/models/db
TruncateBeans
TruncateBeansCascade
InTransaction
DumpTables
GetTableNames
extendBeansForCascade
IsErrNameActivityPubInvalid
forgejo.org/models/dbfs
file.renameTo
Create
Rename
forgejo.org/models/forgejo/semver
GetVersion
SetVersionString
SetVersion
forgejo.org/models/forgejo_migrations
resetMigrations
forgejo.org/models/git
RemoveDeletedBranchByID
forgejo.org/models/issues
IsErrUnknownDependencyType
IsErrIssueWasClosed
forgejo.org/models/organization
SearchMembersOptions.ToConds
forgejo.org/models/perm/access
GetRepoWriters
forgejo.org/models/user
IsErrUserWrongType
IsErrExternalLoginUserAlreadyExist
IsErrExternalLoginUserNotExist
NewFederatedUser
IsErrUserSettingIsNotExist
GetUserAllSettings
DeleteUserSetting
GetFederatedUser
forgejo.org/modules/activitypub
NewContext
Context.APClientFactory
forgejo.org/modules/assetfs
Bindata
forgejo.org/modules/auth/password/hash
DummyHasher.HashWithSaltBytes
NewDummyHasher
forgejo.org/modules/auth/password/pwn
WithHTTP
forgejo.org/modules/base
SetupGiteaRoot
forgejo.org/modules/cache
WithNoCacheContext
RemoveContextData
forgejo.org/modules/emoji
ReplaceCodes
forgejo.org/modules/eventsource
Event.String
forgejo.org/modules/forgefed
NewForgeFollow
NewForgeUndoLike
ForgeUndoLike.UnmarshalJSON
ForgeUndoLike.Validate
NewPersonIDFromModel
GetItemByType
JSONUnmarshalerFn
NotEmpty
ToRepository
OnRepository
forgejo.org/modules/git
AllowLFSFiltersArgs
AddChanges
AddChangesWithArgs
CommitChanges
CommitChangesWithArgs
IsErrMoreThanOne
SetUpdateHook
openRepositoryWithDefaultContext
ToEntryMode
forgejo.org/modules/gitrepo
GetBranchCommitID
GetWikiDefaultBranch
forgejo.org/modules/graceful
Manager.TerminateContext
Manager.Err
Manager.Value
Manager.Deadline
forgejo.org/modules/hcaptcha
WithHTTP
forgejo.org/modules/hostmatcher
HostMatchList.AppendPattern
forgejo.org/modules/json
StdJSON.Marshal
StdJSON.Unmarshal
StdJSON.NewEncoder
StdJSON.NewDecoder
StdJSON.Indent
forgejo.org/modules/log
NewEventWriterBuffer
forgejo.org/modules/markup
GetRendererByType
RenderString
IsMarkupFile
forgejo.org/modules/markup/console
Render
RenderString
forgejo.org/modules/markup/markdown
RenderRawString
forgejo.org/modules/markup/mdstripper
stripRenderer.AddOptions
StripMarkdown
forgejo.org/modules/markup/orgmode
RenderString
forgejo.org/modules/process
Manager.ExecTimeout
forgejo.org/modules/queue
newBaseChannelSimple
newBaseChannelUnique
newBaseRedisSimple
newBaseRedisUnique
testStateRecorder.Records
testStateRecorder.Reset
newWorkerPoolQueueForTest
forgejo.org/modules/queue/lqinternal
QueueItemIDBytes
QueueItemKeyBytes
ListLevelQueueKeys
forgejo.org/modules/setting
NewConfigProviderFromData
GitConfigType.GetOption
InitLoggersForTest
forgejo.org/modules/sync
StatusTable.Start
StatusTable.IsRunning
forgejo.org/modules/timeutil
GetExecutableModTime
MockSet
MockUnset
forgejo.org/modules/translation
MockLocale.Language
MockLocale.TrString
MockLocale.Tr
MockLocale.TrN
MockLocale.TrPluralString
MockLocale.TrPluralStringAllForms
MockLocale.TrSize
MockLocale.HasKey
MockLocale.PrettyNumber
forgejo.org/modules/translation/localeiter
IterateMessagesContent
forgejo.org/modules/util
OptionalArg
forgejo.org/modules/util/filebuffer
CreateFromReader
forgejo.org/modules/validation
IsErrNotValid
forgejo.org/modules/web
RouteMock
RouteMockReset
forgejo.org/modules/zstd
NewWriter
Writer.Write
Writer.Close
forgejo.org/routers/web/org
MustEnableProjects
forgejo.org/services/context
GetPrivateContext
forgejo.org/services/federation
FollowRemoteActor
forgejo.org/services/notify
UnregisterNotifier
forgejo.org/services/repository
IsErrForkAlreadyExist
forgejo.org/services/repository/files
ContentType.String
RepoFileOptionMode
forgejo.org/services/repository/gitgraph
Parser.Reset
forgejo.org/services/stats
Flush
forgejo.org/services/webhook
NewNotifier