Describe at least two of the most commonly used API security mechanisms in the security schemes object of the MediaWiki REST API OpenAPI description.
- Suggestion: CSRF, OAuth 2.0, MW Session
For more information, see the parent task: T422484.
Describe at least two of the most commonly used API security mechanisms in the security schemes object of the MediaWiki REST API OpenAPI description.
For more information, see the parent task: T422484.
| Status | Subtype | Assigned | Task | ||
|---|---|---|---|---|---|
| Open | KBach | T422476 [Hypothesis] 5.2.5b: Productionalize API spec linting | |||
| Open | None | T422484 [5.2.5b Epic] Add security mechanism information to the MediaWiki REST API description | |||
| In Progress | KineticPelagic | T423552 [SPIKE] Add security scheme information to MediaWiki REST API description |
Notes from estimation:
Other notes for estimation that came up during a meeting with @BPirkle and @KineticPelagic:
cc. @KBach, @HCoplin-WMF
Notes from estimation:
Two ways of doing this come to mind:
One option is to focus on just the security schema. Rather than focusing on specific extensions or authentication types, I'd suggest looking at the SessionProvider class and SessionProviderInterface. The SessionManager::getProviders() function will return all configured session providers for a particular wiki. Extensions that provide authentication mechanisms mark themselves as session providers (here's where OAuth does it).
The idea is that the OpenAPI spec generation code would iterate the available session providers on the wiki and interrogate each to find out how to list it in the security schemes object. Hopefully the session provider already makes the necessary information available (SessionProviderInterface::safeAgainstCsrf() is probably relevant, as that determines if a CSRF token is needed or not). If all the necessary info is not available, we could consider adding it (adding stuff to an existing interface is a little tricky, but there are always ways to approach the problem).
Alternatively, we could consider the security scheme need as just one example of a more general challenge: what happens if something an extension does modifies how the OpenAPI spec should be generated? I'm not sure whether or not we'll run into any other cases of that, but if so, we currently don't have a great way to handle it. We could consider adding a hook allowing extensions to fiddle with the fully-generated OpenAPI spec (as a PHP array) before it is returned. That'd solve this entire class of need, at the cost of being something of a blunt tool. New hooks shouldn't be added lightly, and they're not always a great design pattern. I suspect that doing this for security schemes would lead to a decent amount of copy-paste code across extensions. But I bring it up as an option just to make sure we've considered it.
If we can get all the necessary information from the existing session-related classes, I'd recommend going that way. That would be non-intrusive, fairly straightforward, and wouldn't have ripple-effect changes or be hard to reverse if we later change course.
If the necessary information is not available, then we should consider what would be needed to add it and then decide how we feel.
@aaron , am I missing any better ideas about how to do all this?
In general I think the spec of an API module should be the same no matter where that module is installed. Extensions changing APIs provided by other components is something that proved problematic in the action API. It also makes versioning less meaningful. Ideally, the spec should tell a client what it can expect from an API module, no matter on which domain it is called.
That said, the security scheme is probably a notable exception to this rule. It's really not a property of the API but of the site, but OpenAPI doesn't quite model it that way.
So I agree with Bill: Focus on the security use-case, get the relevant information from the authentication manager / session provider, and inject it into the spec. And try to keep it as isolated as possible.