René's URL Explorer Experiment


Title: fix(security): bind copilot chat attachment keys to their owner by waleedlatif1 · Pull Request #6179 · simstudioai/sim · GitHub

Open Graph Title: fix(security): bind copilot chat attachment keys to their owner by waleedlatif1 · Pull Request #6179 · simstudioai/sim

X Title: fix(security): bind copilot chat attachment keys to their owner by waleedlatif1 · Pull Request #6179 · simstudioai/sim

Description: Problem POST /api/copilot/chat accepted a client-supplied fileAttachments[].key and passed it straight into trackChatUpload(), which wrote it into the workspace_files ownership-binding row with no permission check and no key-ownership validation. workspace_files.key is the trusted binding that verifyFileAccess() and the whole workspace Files feature resolve authorization from. The sibling registration path (POST /api/workspaces/[id]/files/register) enforces the invariant explicitly; the copilot attachment path did not. Net effect: a read-only workspace member could take any other member's workspace file, re-bind it to their own private copilot chat, and make it disappear from the workspace — a write/delete capability reached from a read-only grant. The UPDATE matched on (key, workspaceId, deletedAt IS NULL) only. It set context='mothership', which removes the row from every workspace-file query (Files tab, folders, download-by-id, restore), and re-parented chatId to the attacker's chat — where copilot_chats.id ON DELETE CASCADE hard-deletes the victim's row when that chat is deleted. When no active row matched, the INSERT branch minted a fresh binding claiming a foreign object for the caller's workspace. Fix trackChatUpload — treat s3Key as untrusted, applying the invariants the direct-upload path already enforces: Reject keys that do not resolve to the target workspace (parseWorkspaceFileKey). Only two outcomes are claimable: the caller already owns an active chat-upload row for the key, or the key has no workspace_files record at all. Another member's row, a context='workspace' file, and soft-deleted records are all rejected. (Soft-deleted matters: the active-key unique index is partial on deleted_at IS NULL, so an INSERT over an archived row would succeed and grant read access to its bytes.) The UPDATE re-asserts every ownership predicate rather than trusting the row id captured by the lookup, so the statement itself is the atomic check. A concurrent materialize_file sets context='workspace' and clears chatId on the same row; an id-only predicate would drag that saved file back into chat scope. The binding is a compare-and-swap on chat_id (IS NULL OR = target). Two overlapping requests both observe an unbound row; only the first wins, and the loser fails closed instead of stealing the upload and its delete-cascade lifecycle. This also makes an upload bind to exactly one chat, matching the 409 the sibling local-files/stage route already returns. Verify the object exists in storage before minting a new binding. This is hygiene, not authorization, so only a definitive not-found rejects — headObject rethrows provider 5xx/throttles, and failing there would drop a legitimate >50MB multipart upload (the only path that reaches this branch). buildCopilotRequestPayload — gate attachment tracking on write/admin via the shared permissionSatisfies predicate, the same grant /api/files/presigned, /api/files/multipart and /api/files/upload already require to issue these keys. local-files/stage route — an ownership rejection is a client error; return 403 instead of 500. Backward compatibility Audited explicitly for regressions to legitimate users: All upload paths still work. insertFileMetadata passes context through verbatim as 'mothership' with chatId null, so presigned and the no-cloud-storage fallback land on the UPDATE branch; multipart persists no row and lands on INSERT. Its restore branch also clears deleted_at, so re-uploading revives a soft-deleted row before tracking sees it. Key format. All four live key-minting paths emit workspace/{workspaceId}/…. sanitizeFileName collapses names to [A-Za-z0-9.\-_] and never returns empty, so the pattern holds for unicode, spaces, long names and dotfiles. A pre-#1785 prefix-less format exists but is unreachable — trackChatUpload postdates it and every key is freshly minted in the same request. No permission tier loses access. Owners get admin via an explicit row; org owners/admins are derived admins; the route is session-only (no API-key principal). A read member cannot obtain a key in the first place, since all three upload routes already gate on write. No client flow relinks a key across chats. Drafts are scoped per workspaceId:chatId and cleared on submit; every queue/retry/abort-resume path replays under a pinned chat id; no UI attaches an already-uploaded file into a new chat; forking copies blobs to fresh keys. Tests bunx vitest run lib/uploads lib/copilot app/api/files app/api/mothership app/api/workspaces — 1718 passed. Typecheck clean; bun run check:api-validation passes. Fifteen new tests cover the ownership contract, the atomicity predicate, the chat compare-and-swap, and the transient-probe tolerance. Each was verified to fail against the unfixed code — reverting the manager turns the ownership/atomicity/CAS tests red, and reverting the gate turns the permission tests red. Not live-tested. Recommended smoke before production: attach a small file and a >50MB file in a chat and confirm the model reads both, then materialize_file one and confirm it appears in Files and the chat still sends. That covers the UPDATE branch, the INSERT + headObject branch, and the materialize interaction.

Open Graph Description: Problem POST /api/copilot/chat accepted a client-supplied fileAttachments[].key and passed it straight into trackChatUpload(), which wrote it into the workspace_files ownership-binding row with no ...

X Description: Problem POST /api/copilot/chat accepted a client-supplied fileAttachments[].key and passed it straight into trackChatUpload(), which wrote it into the workspace_files ownership-binding row with no ...

Opengraph URL: https://github.com/simstudioai/sim/pull/6179

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b236c479-bb8d-1246-2ca5-ceb8fb901f75
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9AA6:5A71D:7846C1:A59110:6AFB43B2
html-safe-noncefd1ada3897f183c91e9bbc966308a8d9851487a9bdc021ca9e744da379fb2e02
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUE2OjVBNzFEOjc4NDZDMTpBNTkxMTA6NkFGQjQzQjIiLCJ2aXNpdG9yX2lkIjoiNTM1MTc5ODg3MzQ3NzgyNTQ1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8060fe55563b877af05820bf94033df93b9386672c66b247b7388fe159b234a7
hovercard-subject-tagpull_request:4186262707
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6179/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altProblem POST /api/copilot/chat accepted a client-supplied fileAttachments[].key and passed it straight into trackChatUpload(), which wrote it into the workspace_files ownership-binding row with no ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea6c2f87cbcb6414452377b4967858ed6a66f1109
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6179/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6179%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6179%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/6179/files
Reloadhttps://github.com/simstudioai/sim/pull/6179/files
Reloadhttps://github.com/simstudioai/sim/pull/6179/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests200 (200)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
fix/copilot-attachment-key-ownershiphttps://github.com/simstudioai/sim/tree/fix/copilot-attachment-key-ownership
Conversation 14 https://github.com/simstudioai/sim/pull/6179
Commits 5 https://github.com/simstudioai/sim/pull/6179/commits
Checks 28 https://github.com/simstudioai/sim/pull/6179/checks
Files changed https://github.com/simstudioai/sim/pull/6179/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6179/files
fix(security): bind copilot chat attachment keys to their owner https://github.com/simstudioai/sim/pull/6179/files#top
Show all changes 5 commits https://github.com/simstudioai/sim/pull/6179/files
6023670 fix(security): bind copilot chat attachment keys to their owner waleedlatif1 Aug 2, 2026 https://github.com/simstudioai/sim/pull/6179/commits/6023670405123d7d2238db4a04aee42216cf1c08
bd7906a fix(security): make the chat-upload ownership check atomic with its w… waleedlatif1 Aug 2, 2026 https://github.com/simstudioai/sim/pull/6179/commits/bd7906af0f5d72f1802ebe99a1f689cd370c1ae0
760f07a fix(uploads): tolerate transient storage probes and reject unowned ke… waleedlatif1 Aug 2, 2026 https://github.com/simstudioai/sim/pull/6179/commits/760f07a7da8d77ca2f42b3db2592784fb2dc0ab3
d88c822 fix(security): compare-and-swap the chat binding on chat uploads waleedlatif1 Aug 2, 2026 https://github.com/simstudioai/sim/pull/6179/commits/d88c822f8cf906ce6fc512547ebf5c2b127e4909
175d608 refactor(copilot): gate attachment tracking with the shared permissio… waleedlatif1 Aug 2, 2026 https://github.com/simstudioai/sim/pull/6179/commits/175d608ba7f700ca711991a03d3fd6fb982aa2d1
Clear filters https://github.com/simstudioai/sim/pull/6179/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6179/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6179/files
route.ts https://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
payload.test.ts https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
payload.ts https://github.com/simstudioai/sim/pull/6179/files#diff-8784913f594d3817f6261ccbbcc7cfb575ce191fa3cb47f4f258fc263d12123c
track-chat-upload.test.ts https://github.com/simstudioai/sim/pull/6179/files#diff-fc551b1b39c7033e277ea1693d0e788c119dad93bde742a29ad55d5be16afe2a
workspace-file-manager.ts https://github.com/simstudioai/sim/pull/6179/files#diff-fcf305d0b37403347596bca42fc6889e9038c9f8e2c69ba20676c0f0d8fead34
apps/sim/app/api/mothership/local-files/stage/route.tshttps://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
View file https://github.com/simstudioai/sim/blob/175d608ba7f700ca711991a03d3fd6fb982aa2d1/apps/sim/app/api/mothership/local-files/stage/route.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6179/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
https://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
https://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
https://github.com/simstudioai/sim/pull/6179/files#diff-743f5f9640454b5e0e951b45f1a5bcc3c8c384a812a6f805af312398fde4ff24
apps/sim/lib/copilot/chat/payload.test.tshttps://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
View file https://github.com/simstudioai/sim/blob/175d608ba7f700ca711991a03d3fd6fb982aa2d1/apps/sim/lib/copilot/chat/payload.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6179/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
https://github.com/simstudioai/sim/pull/6179/files#diff-80cd1ca77f8236354c9fb18e96b0fda2b559b8aa3be5f12813ab01440e2e9c43
apps/sim/lib/copilot/chat/payload.tshttps://github.com/simstudioai/sim/pull/6179/files#diff-8784913f594d3817f6261ccbbcc7cfb575ce191fa3cb47f4f258fc263d12123c
View file https://github.com/simstudioai/sim/blob/175d608ba7f700ca711991a03d3fd6fb982aa2d1/apps/sim/lib/copilot/chat/payload.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6179/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6179/files#diff-8784913f594d3817f6261ccbbcc7cfb575ce191fa3cb47f4f258fc263d12123c
https://github.com/simstudioai/sim/pull/6179/files#diff-8784913f594d3817f6261ccbbcc7cfb575ce191fa3cb47f4f258fc263d12123c
https://github.com/simstudioai/sim/pull/6179/files#diff-8784913f594d3817f6261ccbbcc7cfb575ce191fa3cb47f4f258fc263d12123c
Please reload this pagehttps://github.com/simstudioai/sim/pull/6179/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6179/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.