Add JSONP support to the modConnectorResponse #12420
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When returning an array from a processor->process function, the modConnectorResponse can turn that into a nice JSON response. With this patch, it can also support JSONP by looking at a "callback" get parameter, and returning the json wrapped in that.
This makes it easier to use the connector/processor approach for cross-site stuff, while also allowing the $modx->runProcessor response (modProcessorResponse) to remain useful from within snippets or stuff like that. The approach to JSONP prior to this patch would be to prepare the specific JSONP format in the process() function of the processor, after which you'll need to strip it out again if you want to re-use the processor through $modx->runProcessor(), which sucks.
I have some slight concerns if there may be security implications by adding this, discussed below, but all considered I think it is a safe addition.
$_GET['callback']without sanitisation - that could potentially be used to inject arbitrary javascript into the response, but given that javascript would be executed on the requester, any hypothetical attacker would already have access to run arbitrary code or XSS on that requester. Also, sanitisation could break a legitimate callback, so some comments you see online are that you should just make sure it is valid, and return a 400 Bad Request if it isn't.