When I develop a site, I'm always conscious of security flaws, but I'm struggling to see how a search box could ever be used to inject script that could be ran on a page of mine.
So I understand that, from a lack of sanitization, input may be added to my DOM. But - so what? I never expect a user to use javascript as a search term - so I'll never attempt to run it on my page. I'll treat it as a string, and so it will only ever behave like one. Or am I missing something fundamental here?
The only time I may add some input to the page is if I render No search results found for "<script>malicious();</script>"
, but I'll never let the search term run.
What am I misunderstanding here?
In fact, if anybody can explain aside from the search box concept - I'm happy with that. I'm struggling to grasp that last part of an XSS attack.