- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Surprising feature on MacOS: empty service/account strings are wildcards #86
Comments
Great catch, @cvermilion, thanks! I'm inclined to simply refuse empty user names, since that could easily be made consistent behavior across all platforms, and it would conceal this Apple-specific "wildcard" feature (which can't be exposed by keyring in a cross-platform way. because it doesn't exist on Windows). |
Yeah, I think that's a good plan. The "search if empty" feature sort of makes sense if you're familiar with the Apple APIs but otherwise is probably unexpected, so I don't think forbidding empty fields is a big loss. If someone wants this behavior on Mac/iOS they can use |
So looking at the code, there's really no way of putting a general fix in without changing the API or allowing the code to panic. This is because the signatures for
I'm inclined to the latter, as this doesn't seem like it's worth altering the API for. @hwchen what do you think? |
FWIW, I think that's a sensible approach, and #87 looks fine to me. Allowing I'm not sure whether it's worth worrying about users who relied on this behavior -- it seems possible that someone who worked exclusively on Mac/iOS might have expected and used it. But given that it's undocumented and non-portable, I'd say it's probably ok to remove? |
Thanks for the review and the thoughtful comments! It's hard to believe anyone is actually relying on this on macOS/iOS, since it only works if the credential you're working with is either the only one with that service name or magically the "first" one the keyring decides to return. My bigger concern is that someone might explicitly be using an empty username or service name in order to be compatible with a 3rd-party application. If so, they are going to be a bit surprised. But, since the behavior in that case is undocumented and varies across platforms, I feel OK about clarifying it. They can still access the existing functionality by using the This discussion makes me think, however, that this should probably be a minor version release not a patch release, and I should add some explicit deprecation documentation to the release notes, as well as a warning that the next major release will probably do validation at |
@cvermilion @hwchen I've updated the PR #87 per my last comment. I'll merge later today or tomorrow unless someone objects. |
The underlying Security Framework functions take optional arguments for the service and account strings, but this bubbles up to
keyring
as plain&str
s. Passing an empty string is then treated as a non-provided optional argument rather than an explicit empty value. So, for example:I've only tested this on MacOS but I suspect the behavior is the same on iOS.
This makes some sense as a reflection of the underlying API, but just reading the docs for
keyring
, I think it's a very surprising behavior. I think this should either a) get clear documentation somewhere, b) be forbidden (just fail on empty values somewhere) or c) be reflected in the API by making the service/account paramsOption
s.The text was updated successfully, but these errors were encountered: