Reputation: 323
I have multiple jsp files in which I want to do something like this in order to avoid XSS. Basically use JSTL to escape the "value".
//change following line to use c:out
<input type="hidden" id="crudProperty1" name="crudProperty1" value="${crud.property1}"></input>
<input type="hidden" id="crudProperty1" name="crudProperty1" value="<c:out value="${crud.property1}"/>"></input>
Here's the script that I tried to use from the terminal, to do these changes for one of the files in a folder.
find . -type f -name "*.jsp" | xargs perl -i -p -e 's|" value=("\${.*}"?)|" value="<c:out value=\1/>"|'
This is essentially looking for any .jsp files, then looping over the output abd replacing the above mentioned text in-place. I am not quite sure what is going wrong, but I do not see any changes to the file. Any help with this would be appreciated.
Upvotes: 0
Views: 51
Reputation: 89547
You don't need to use perl and xargs, you can do this task only with sed:
find . -type f -name "*.jsp" -exec sed -i 's#\(value="\)\(\${[^}]*}\)"#\1<c:out \1\2/>"#g' {} \;
Upvotes: 2