Suspended, inactive and blocked user with API key can still create topics

AI-generated summary

gtanczyk reported a bug where a suspended and inactive user could still create topics via the REST API using a specific Ruby script, despite category security settings being respected. The user intended to commit a read-only API key to an open-source repository for downloading topics to a static site. sam clarified that skip_validations: true is an API-only feature and stated that API keys must be manually revoked when a user is suspended, noting that read-only JSON endpoints do not require an API key. codinghorror suggested adding a check for suspended users in the API and proposed that the suspend action should automatically revoke any associated API keys. gtanczyk confirmed the immediate issue was resolved by revoking the key but emphasized that automatic revocation would be more intuitive. Finally, zogstrip announced that the feature to automatically revoke API keys upon suspending, blocking, or deactivating a user has been implemented in the codebase.

User is configured like this:

Inactive and suspended, yet I am still able to create topic with following code:

@data = {
  skip_validations: true,
  auto_track: false,
  title: "test",
  raw: "test"
}
resp = client.create_topic(@data)

Is this intended behavior? On the other hand category security settings are respected.

What I am trying to achieve: I have open source project with simple ruby script that downloads latest topics from some particular discourse instance and converts that to a static web site.
I would like to commit this API key for read only user, so everyone can clone this repo and start their work.

Is there any other way to achieve this(read-only user with api access)?

Thanks

Edit: It also doesn’t work when user is blocked

4 Likes

Only API is allowed to do this. We never intended to allow API usage to general public, if you suspend a user you must revoke their keys.

Hmmm, for read only access you don’t need any API key, all the json endpoints work fine without it.

Probably Ok to add a check here in API for suspended user, but this seems like a super freakish edge case to me…

Perhaps the suspend action could auto revoke any API keys this user holds?

5 Likes

Thanks for tip @sam, problem is gone.

Revoking api keys on suspend/block/deactivate would be far more intuitive.

That’s now done :rat:

https://github.com/discourse/discourse/commit/73624e63c52f915c1530d29a965cee9d0ae2de7d

3 Likes