0

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.

3
  • 1
    Using perl is overkill for this task, sed can do the job. Commented Sep 11, 2015 at 19:37
  • 1
    I tried your script and it is working for me (perl v5.20.2). Commented Sep 11, 2015 at 21:05
  • Thanks for the comment. It was actually working fine but there was an issue with the space before value in the regex. Thanks anyways! Commented Sep 15, 2015 at 21:49

1 Answer 1

2

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' {} \;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, This does it perfectly fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.