Skip to content

Fix file proviver extension to ONLY write to its own cached secret in keychain. - #10858

Closed
stuckj wants to merge 1 commit into
nextcloud:masterfrom
stuckj:fix/macos-keychain-scope-queries-by-service
Closed

stuckj wants to merge 1 commit into
nextcloud:masterfrom
stuckj:fix/macos-keychain-scope-queries-by-service

Conversation

@stuckj

@stuckj stuckj commented Sep 17, 2026

Copy link
Copy Markdown

Resolves

#9865 (partially). This bug covers many things, but the topic diverged a bit. I can create a new bug for the specific item this fixed, if desired.

Summary

Use a namespaced service string based on server URL to reliably scope the keychain entry to OUR entry instead of another applications. 😬 Without this, we sometimes are updating a different applications keychain entry since it's basically only matching based on username (the account name).

From what I can tell, the credentials in the file provider are for cache purposes only. In my test, I ran an unpatched version I built first. I had to authenticate since it was sandboxed with my personal credentials. I verified that reproduced the bad behavior. I then re-built with the patched version and killed/restarted the app. That then did NOT exhibit the behavior and the filesystem was still accessible. So, credentials appear unaffected after the change.

AI was used to help identify the problem, draft a patch, and help with build setup (since I haven't worked in this project before). I verified the patch makes sense (it's only a few lines) and that it works by building/testing locally. I'm a developer with 30 years experience so I appreciate the easier onboarding it provides, but don't trust it to do stuff on its own.

TODO

Nothing

Checklist

AI (if applicable)

Reliably scope the keychain entry to OUR entry instead of another
applications. 😬

Signed-off-by: Jonathan Stucklen <stuckj@gmail.com>
Assisted-by: ClaudeCode:claude-opus-5
@stuckj stuckj changed the title Fix file proviver extension to ONLY write to it's own cached secret in keychain. Fix file proviver extension to ONLY write to its own cached secret in keychain. Sep 17, 2026
@i2h3

i2h3 commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

From what I can tell, the credentials in the file provider are for cache purposes only.

It actually was a workaround to avoid users receiving errors in Finder that they are not signed in. The run-time provisioning of the file provider extension process by the main app process through UNIX sockets (meanwhile migrated to pure XPC) did not work reliably in the past.

The best would be a keychain sharing group entitlement but for historical reasons (it would render all these measures obsolete), this is impossible for our used identifiers right now.

@i2h3 i2h3 self-assigned this Sep 18, 2026
@i2h3

i2h3 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

…so I tried to amend my comment two dozen times since I wrote it but then German train Wi-Fi struck again and I had to wait until now for proper conference Wi-Fi. 🤪 I was not aware that apps can query all items. This then looks like a serious oversight, indeed. Then I asked myself why there even is the keychain group access entitlement but I assume to avoid the access authorization prompts.

@i2h3 i2h3 added this to the 35.0.1 milestone Sep 19, 2026
@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 💻 Desktop Clients team Sep 19, 2026
@i2h3 i2h3 added bug os: 🍎 macOS Apple macOS, formerly also known as OS X feature: 📁 file provider macOS File Provider Extension, more general also known as virtual file system. labels Sep 19, 2026
@i2h3 i2h3 moved this from 🧭 Planning evaluation (don't pick) to 🏗️ In progress in 💻 Desktop Clients team Sep 19, 2026
@i2h3

i2h3 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

/backport to stable-34.0

/// Scopes an item to this application and server, so a lookup cannot match an item
/// belonging to another application.
private func service(for server: String) -> String {
"com.nextcloud.desktopclient:\(server)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs amendment. Our desktop client is a customizable project. The bundle identifier used as the prefix must be looked up during runtime and not be a compile time constant. I will look for more details on how to do this best here and follow up.

@i2h3 i2h3 Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, the keychain item could also include the raw file provider domain identifier which is a life time UUID. Then server address and bundle identifiers become unnecessary because ownership and uniqueness are already achieved.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@i2h3, it sounds like you're taking care of modifications here. But, if you need any additional input or changes from me, please just ping me directly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I thought my request for changes and the input I commented was clear enough. 😅 I think I finally understood the matter thanks to your comment and pull request. I try to work on this ASAP.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a stab at the changes. :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuckj I did not see your comment yet in the flood of notifications, sorry. I opened #10981 meanwhile which is ought to replace this PR. I gave you credit for discovering and starting this fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@phk1918

phk1918 commented Sep 29, 2026

Copy link
Copy Markdown

I can confirm this bug on Nextcloud desktop 34.0.4, macOS 27.0.1 (arm64).

The login keychain item Claude Code-credentials (Anthropic's Claude Code, account = my macOS username = my Nextcloud login name) is modified about 2 seconds after every Nextcloud start. Its partition list is reset to teamid:NKUJUXUJ3B, so the owning app triggers a "security wants to access key" prompt on every access, and "Always Allow" does not persist.

Observed timings:

  • Nextcloud started 13:54:04 → item mdat 13:54:06
  • Nextcloud started 13:40:18 → item mdat 13:40:41

It would be great to get this merged.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@i2h3

i2h3 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Closed because replaced with #10981.

@i2h3 i2h3 closed this Oct 2, 2026
@github-project-automation github-project-automation Bot moved this from 🏗️ In progress to ☑️ Done in 💻 Desktop Clients team Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-request bug feature: 📁 file provider macOS File Provider Extension, more general also known as virtual file system. feedback-requested os: 🍎 macOS Apple macOS, formerly also known as OS X

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS client modifies another app's keychain item on startup (sets partition list to teamid:NKUJUXUJ3B), breaking Claude Code

3 participants