fix(api): enforce team ownership check before tag resolution in PostTemplatesTags - #3574
Open
chill-czar wants to merge 1 commit into
Open
fix(api): enforce team ownership check before tag resolution in PostTemplatesTags#3574chill-czar wants to merge 1 commit into
chill-czar wants to merge 1 commit into
Conversation
chill-czar
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
August 17, 2026 19:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3573
Summary
aliasInfo.TeamID != team.IDteam ownership authorization check inPostTemplatesTagsimmediately aftera.templateCache.ResolveAlias, before opening database transactions or executingqueries.GetTemplateWithBuildByTag.404 Not Foundvs403 Forbiddenresponses.WithTx) on unowned templates.TestPostTemplatesTags_RejectsOtherTeamTemplateasserting403 Forbiddenearly.Why
In
packages/api/internal/handlers/template_tags.go,PostTemplatesTagspreviously executedqueries.GetTemplateWithBuildByTaginside a database transaction before checking team ownership. If a tag was not present on an unowned template, the handler returned 404 from the query error before reaching the 403 authorization check at line 115. Moving the check immediately afterResolveAliasmatches the structure inDeleteTemplatesTagsandGetTemplatesTemplateIDTags, preventing metadata leakage and saving database transaction overhead.Diff Overview
aliasInfo, err := a.templateCache.ResolveAlias(ctx, templateID) if err != nil { a.sendAPIStoreError(c, http.StatusNotFound, fmt.Sprintf("Template '%s' not found: %s", templateID, err)) return } + if aliasInfo.TeamID != team.ID { + a.sendAPIStoreError(c, http.StatusForbidden, fmt.Sprintf("You don't have access to sandbox template '%s'", templateID)) + return + } + txErr := a.sqlcDB.WithTx(ctx).Exec(func(queries *queries.Queries) error { build, err := queries.GetTemplateWithBuildByTag(ctx, queries.GetTemplateWithBuildByTagParams{ TemplateID: aliasInfo.TemplateID, Tag: &tag, })Test Plan
go test -v ./packages/api/internal/handlers -run TestPostTemplatesTags_RejectsOtherTeamTemplatego test -v ./packages/api/internal/handlers/...make fmtandmake lint403 Forbiddenregardless of whether the tag exists or does not exist/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi