feat: limit access to job file endpoints to only the same user as requester - #140
Open
Yash Shrivastava (alephys26) wants to merge 6 commits into
Open
feat: limit access to job file endpoints to only the same user as requester#140Yash Shrivastava (alephys26) wants to merge 6 commits into
Yash Shrivastava (alephys26) wants to merge 6 commits into
Conversation
Copilot started reviewing on behalf of
Yash Shrivastava (alephys26)
August 26, 2026 17:13
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR closes an access-control gap in the Heimdall API’s job file endpoints by enforcing that only the job owner (as identified by the existing auth header middleware) can fetch a job’s stdout, stderr, or result payloads.
Changes:
- Switched job lookup in
getJobFilefromgetJobStatustogetJobso the job owner (User) is available for authorization checks. - Added an ownership check (
j.UservsgetUsername(r)) returningErrCallerNotAllowed(403) on mismatch. - Consolidated the job type assertion and preserved the existing “result only when succeeded” guard.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
sanketjadhavSF
approved these changes
Aug 27, 2026
prasadlohakpure
approved these changes
Aug 28, 2026
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.
PR details
Background
/job/{id}/resulthad no ownership check. Any caller who knew or guessed a job ID could read another user's job result, even without identifying themselves. Heimdall already identifies the caller via theauth_headerplugin (X-Heimdall-User, stored asj.Useron job creation), so the fix enforces that the requester matches the job's owner before serving the result file.Changes
getJobFile(internal/pkg/heimdall/job.go), scoped to theresultfile: the job is looked up viagetJobStatusand itsUsercompared againstgetUsername(r)(the caller identity from the existing auth middleware); mismatches are rejected withErrCallerNotAllowed(403).stdout/stderrare unaffected — no ownership restriction is added for those.queries/job/status_select.sqlto also selectj.username, and scan it intor.UseringetJobStatus(job_dal.go), so the ownership check can run off the existing lightweight status query instead of the fullgetJoblookup (which loads job context/tags and would have made the file-download path heavier and introduced unrelated failure modes — per review feedback).job_dal.go.Types of changes
Tests
Ran the backend locally (postgres + heimdall API), submitted a
pingjob as useralice, and hit/job/{id}/resultand/job/{id}/stdout:alice(owner)result:200 OK, correct bodybob(non-owner)result:403 caller is not allowed to run this commandX-Heimdall-Userheaderresult:403 caller is not allowed to run this commandalicestdout:200 OK(unrestricted, as intended)bobstdout:200 OK(unrestricted, as intended)go build ./internal/... ./pkg/...passes.Impact
Restricts
/job/{id}/resultto the job's owner only; any other caller now gets403there./job/{id}/stdoutand/job/{id}/stderrremain unchanged (no access restriction). No schema or API contract changes beyond the new403response forresult.