I have a Java API that accepts a custom CSS field. I need to sanitize the CSS before storing it in my database and would like to use Google Caja for this.
First, I tried running the Google Caja HTML/CSS sanitizer JavaScript library using the Rhino JavaScript engine. Unfortunately, that didn't work because that library depends heavily on the existence of a DOM (specifically, the window object).
Next, I imported the Caja project from the Maven repository. I looked through some of the tests, but could not find an example of how to use the sanitizer.
I could try bringing the browser to the server, but that seems a bit excessive.
Has anyone been able to use Caja to sanitize a CSS string in Java?
Thanks in advance!
Google Caja is also a "Java project" and therefore you can execute anything Caja can do directly in java. For example, you can take a look to a Caja unit test case to validate the CSS directly in java here.