I have an application that talks to Redmine/Chiliproject using its API with results in JSON. I use ActiveResource to make these calls, and it suddendly started failing after an upgrade from redmine to chiliproject:
The fact that I was getting an error from ActiveRecord and not ActiveResource was puzzling. My ActiveResource class was called ProjectResource. The thing that I was retrieving was a “project”, and yes, I happened to have a model called “Project”, which was a subclass of ActiveRecord.
Looking at the JSON results using curl:
and also in the debugger, at
what happens next is that the word “project” is passed to
and this finds and returns the “Project” class which is in my model. My model does not have a field created_on, thus the error.
So there three problems with this behaviour:
- additions to the API should not break my old code, I should just ignore them.
- there is no guarantee that the class that was found, “Project” has any of the behaviour that I need in the thing returned from ActiveResource.
- worst, since the word “project” came from the remote system, the remote system could pick any class it wanted and invoke code on it. It’s a reverse attack by a server on a client, but it’s wrong to assume that the server is fully trusted by the client.
I’m not sure what the easiest way to fix this, but it’s certainly wrong, and it’s been there awhile in ActiveResource.