I'm trying to pass a collection of book titles back to a form. Normally in the second step the data is sanitized, however I'm now getting a server error whenever any of the titles have an Ampersand in them in the first step.
<form id="addbsms" method="post" action="?action=addnewbooks&submit=validate" >
<Textarea name="newblist" rows="30" cols="68"></textarea>
<button type="submit" name="Submit" onsubmit="validateForm()">Submit</button>
</form>
I've tried to make a JS to clean up before it submits, but my JS chops aren't great:
<script>
function validateForm(){
let x= document.forms["addnewform"]["newmlist"].value;
return x.replace(/&/g,"and");
}
</script>
And an example of the data that causes this issue:
Cozy cottage & cabin designs : 200+ cottages, cabins, A-frames, vacation homes, apartment garages, sheds & more / Creative Homeowner|Creative Homeowner|2019|9781580118415 (paperback)|NONFICTION|20210813|
( Title|Author|Pub year|ISBN|Type|Classification|Date Added| )
The error Mod_security shows: [Wed Aug 18 12:39:01.559409 2021] [:error] [pid 3772:tid 4255957415680] [client -redacted-] [client -redacted-] ModSecurity: Warning. Pattern match "(?i)(?:;|\\{|\\||\\|\\||&|&&|\\n|\\r|`)\\s*[\\(,@\\'\"\\s](?:[\\w'\"\\./]+/|[\\\\'\"\\^]\\w[\\\\'\"\\^]:.\\\\|[\\^\\.\\w '\"/\\\\]\\\\)?[\"\\^](?:s[\"\\^]*(?:y[\"\\^]s[\"\\^](?:t[\"\\^]*e[\"\\^]m[\"\\^](?:p[\"\\^]*r[\"\\^]*o[\"\\^]*p[\"\\^]*e ..." at ARGS:newblist. [file "/dh/apache2/template/etc/mod_sec3_CRS/REQUEST-932-APPLICATION-ATTACK-RCE.conf"] [line "294"] [id "932115"] [msg "Remote Command Execution: Windows Command Injection"] [data "Matched Data: |\x0d\x0aType R : transformative resilience for thriving in a turbulent world / Ama Marston, Stephanie Marston|Marston, Ama|2018|9781610398060 (hardback)|NONFICTION|20210813|\x0d\x0aUltimate guide : plumbing / [principal author, Merle Henkenius ; contributing author, Steve Willson]|Henkenius, Merle|2021|9781580118613|NONFICTION|20210813|\x0d\x0aUltimate guide : plumbing / [principal author, Merle Henkenius ; contributing author, Steve Willson]|Henkenius, Merle|2021|9781580118613|NONFICTION|..."] [severity "CRITICAL"] [ver [hostname "-redacted-"] [uri "/pageinquestion.php"] [unique_id "YR1h1bWfXoy3zM7JSdfj8QAAAAE"], referer: -fullurl-