Hi everyone,
I am building a custom IdentityIQ plugin that uses a JavaScript snippet on the home page to query a custom plugin REST endpoint (ChatResource).
Even after changing my endpoint method from POST to GET to avoid state-changing CSRF filters, I am still encountering the following security exception in the system logs when the frontend script queries the endpoint:
The Error:
<SyslogEvent classname="sailpoint.server.CsrfService" eventLevel="ERROR">
<EventMessage>CSRF validation failed for /identityiq/plugin/rest/iiqbot/ask</EventMessage>
</SyslogEvent>
ChatResource.java:
@GET
@Path("ask")
public Response ask(@QueryParam("message") String message) {
Map<String, Object> result = new HashMap<>();
try {
SailPointContext context = getContext();
Identity user = getLoggedInUser();
String msg = (message != null) ? message.toLowerCase().trim() : "";
String reply = buildReply(context, user, msg);
result.put("reply", reply);
return Response.ok(result).build();
} catch (Exception e) {
result.put("reply", "An error occurred: " + e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(result).build();
}
}
snippet.js:
jQuery.ajax({
url: restUrl,
type: 'GET',
dataType: 'text',
success: function(res) {
var replyText = (res && res.reply) ? res.reply : "Received empty response from server.";
msgContainer.append('<div class="iiq-bubble iiq">' + replyText + '</div>');
msgContainer.scrollTop(msgContainer[0].scrollHeight);
},
error: function(xhr, textStatus, errorThrown) {
var debugMsg = '<b>Error: ' + textStatus + '</b><br/>Response: ' + xhr.responseText;
msgContainer.append('<div class="iiq-bubble iiq">' + debugMsg + '</div>');
msgContainer.scrollTop(msgContainer[0].scrollHeight);
}
});
My Setup:
-
Java Resource Class: Extends
BasePluginResourcewith@Path("iiqbot")and@AllowAll. -
Method Annotation: Annotated with
@GETand@Path("ask"). -
Frontend Call: Using
PluginHelper.getPluginRestUrl('iiqbot/ask?message=...')viajQuery.ajax.
Why is RestCsrfValidationFilter intercepting and throwing a CsrfValidationException on a @GET request under /plugin/rest/*, and how can I correctly authorize or exempt a custom plugin REST endpoint from this validation?
If i access: http://[ip]:8080/identityiq/plugin/rest/iiqbot/ask, then get “CSRF validation failed” error. In my plugin snippet ui, i get the output mentioned below:
Any help or best practices would be greatly appreciated!
