ci: add semgrep detection for API code ignoring repo-specific access tokens #11476
Labels
No labels
arch
riscv64
backport/v1.19
backport/v1.20
backport/v1.21/forgejo
backport/v10.0/forgejo
backport/v11.0/forgejo
backport/v12.0/forgejo
backport/v13.0/forgejo
backport/v14.0/forgejo
backport/v7.0/forgejo
backport/v8.0/forgejo
backport/v9.0/forgejo
breaking
bug
bug
confirmed
bug
duplicate
bug
needs-more-info
bug
new-report
bug
reported-upstream
code/actions
code/api
code/auth
code/auth/faidp
code/auth/farp
code/email
code/federation
code/git
code/migrations
code/packages
code/wiki
database
MySQL
database
PostgreSQL
database
SQLite
dependency-upgrade
dependency
certmagic
dependency
chart.js
dependency
Chi
dependency
Chroma
dependency
citation.js
dependency
codespell
dependency
css-loader
dependency
devcontainers
dependency
dropzone
dependency
editorconfig-checker
dependency
elasticsearch
dependency
enmime
dependency
F3
dependency
ForgeFed
dependency
garage
dependency
Git
dependency
git-backporting
dependency
Gitea
dependency
gitignore
dependency
go-ap
dependency
go-enry
dependency
go-gitlab
dependency
Go-org
dependency
go-rpmutils
dependency
go-sql-driver mysql
dependency
go-swagger
dependency
go-version
dependency
go-webauthn
dependency
gocron
dependency
Golang
dependency
goldmark
dependency
goquery
dependency
Goth
dependency
grpc-go
dependency
happy-dom
dependency
Helm
dependency
image-spec
dependency
jsonschema
dependency
KaTeX
dependency
lint
dependency
MariaDB
dependency
Mermaid
dependency
minio-go
dependency
misspell
dependency
Monaco
dependency
PDFobject
dependency
playwright
dependency
postcss
dependency
postcss-plugins
dependency
pprof
dependency
prometheus client_golang
dependency
protobuf
dependency
relative-time-element
dependency
renovate
dependency
reply
dependency
ssh
dependency
swagger-ui
dependency
tailwind
dependency
temporal-polyfill
dependency
terminal-to-html
dependency
tests-only
dependency
text-expander-element
dependency
urfave
dependency
vfsgen
dependency
vite
dependency
Woodpecker CI
dependency
x tools
dependency
XORM
Discussion
duplicate
enhancement/feature
forgejo/accessibility
forgejo/branding
forgejo/ci
forgejo/commit-graph
forgejo/documentation
forgejo/furnace cleanup
forgejo/i18n
forgejo/interop
forgejo/moderation
forgejo/privacy
forgejo/release
forgejo/scaling
forgejo/security
forgejo/ui
Gain
High
Gain
Nice to have
Gain
Undefined
Gain
Very High
good first issue
i18n/backport-stable
impact
large
impact
medium
impact
small
impact
unknown
Incompatible license
issue
closed
issue
do-not-exist-yet
issue
open
manual test
Manually tested during feature freeze
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
problem
QA
regression
release blocker
Release Cycle
Feature Freeze
release-blocker
v7.0
release-blocker
v7.0.1
release-blocker
v7.0.2
release-blocker
v7.0.3
release-blocker
v7.0.4
release-blocker
v8.0.0
release-blocker/v9.0.0
run-all-playwright-tests
run-end-to-end-tests
test
manual
test
needed
test
needs-help
test
not-needed
test
present
untested
User research - time-tracker
valuable code
worth a release-note
User research - Accessibility
User research - Blocked
User research - Community
User research - Config (instance)
User research - Errors
User research - Filters
User research - Future backlog
User research - Git workflow
User research - Labels
User research - Moderation
User research - Needs input
User research - Notifications/Dashboard
User research - Rendering
User research - Repo creation
User research - Repo units
User research - Security
User research - Settings (in-app)
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo/forgejo!11476
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "finegrained-pr7-semgrep"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR is part of a series (#11311).
Prevents the usage of three internal APIs in the web API code:
repo_model.SearchRepoOptions{}without anAuthorizationReducerorganization.SearchTeamRepoOptions{}without anAuthorizationReduceraccess_model.GetUserRepoPermission(), which doesn't take anAuthorizationReducer-- useGetUserRepoPermissionWithReducerinstead.A couple lingering usages are marked with
// nosemgrep: ...as they have been inspected and considered correct as-is.The
GetUserRepoPermissionis tested via the.semgrep/testsfiles; the other rules have been tested manually.Checklist
The contributor guide contains information that will be helpful to first time contributors. There also are a few conditions for merging Pull Requests in Forgejo repositories. You are also welcome to join the Forgejo development chatroom.
Documentation
Release notes
@ -171,0 +173,4 @@// permission checks. Repo-specific access tokens aren't expected to be used with `package:write` scope, so// there's currently no need to change this to GetUserRepoPermissionWithReducer -- and because package APIs// doesn't take use an `APIContext`, we don't have access to a reducer to provide to it.//I don't follow. Packages, at least OCI images, can be attached to repositories.
In any case, I find the description a bit unclear. I tried to reword it:
@aahlenst wrote in #11476 (comment):
Repo-specific access tokens will be restricted to only providing the
read:repository,write:repository,read:issue, andwrite:issuescopes. Any other configuration will fail to create an access token (I'm still authoring the PRs to create repo-specific access tokens, so I don't have code to link here). This is the meaning of the statement "Repo-specific access tokens aren't expected to be used withpackage:writescope."I'll take a pass at rewriting this comment to clarify it.
Revision
a274a3d662..a8fef29b10:(The fact that this is a weird access check is removed from the comment because it's irrelevant to the ignore. While packages in general can be linked to repositories, as you've noted, this appears to be the only access check in the package API that looks for permission to write to the linked repository. 🤷 It stands out as a possible mistake, but, not really relevant to why we can ignore repo-specific access tokens here.)
a274a3d662a8fef29b10