Hi, I have researched this issue a bit now but I am still unsure.
I am building a website that uses a jQuery library to handle a terminal input. As far as I know, the library itself sanitizes the user input (commands) already.
Code example snippet is the following:
$('body').terminal(function(command, term) {
if (command === 'run word1') {
term.echo('Text that is displayed when you use word1 command');
} else if (command === 'help') {
term.echo('Help text displayed when you use help command');
Now, I want some of these texts (there are more than the code example) to have links. The library auto-converts any mail address or https:// link to a clickable link, but I want a clickable word basically, like you would usually do as
A specific <a href="www.link.com">word</a> should be a link.
But this doesn't work within the the term.echo texts because they treat the text as plain text, not HTML, so the <a href> would just show up as text. One way to change this is to attach raw: true the following way:
} else if (command === 'run word2') {
term.echo('<a href="link here">Linkword</a> and rest of the text', { raw: true });
This treats the text as raw HTML, and with that, the <a href> works and I can style it in CSS too. However, raw: true can be a security risk because it renders HTML directly, and if I understand correctly, even before the sanitization check.
Am I correct in my assessment that only running the commands themselves as raw:true is a risk, because that is the direct user input, and running raw:true on the text that will show up after the user input is okay?
Or are there any more elegant solutions than this?