Sanitize user input in bash for security purposes

The Short Bash already deals with that. Quoting it is sufficient. ls “$INPUT” The Long A rough guide to how the shell parses this line is: “ls \”$INPUT\”” # Raw command line. [“ls”, “\”$INPUT\””] # Break into words. [“ls”, “\”filename; rm -rf /\””] # Perform variable expansion. [“ls”, “\”filename; rm -rf /\””] # Perform word … Read more

Safely sandbox and execute user submitted JavaScript?

You can use sandbox support in nodejs with vm.runInContext(‘js code’, context), sample in api documentation: https://nodejs.org/api/vm.html#vm_vm_runinthiscontext_code_options const util = require(‘util’); const vm = require(‘vm’); const sandbox = { globalVar: 1 }; vm.createContext(sandbox); for (var i = 0; i < 10; ++i) { vm.runInContext(‘globalVar *= 2;’, sandbox); } console.log(util.inspect(sandbox)); // { globalVar: 1024 } WARN: As … Read more

What’s up with these Unicode combining characters and how can we filter them?

What’s up with these unicode characters? That’s a character with a series of combining characters. Because the combining characters in question want to go above the base character, they stack up (literally). For instance, the case of ก้้้้้้้้้้้้้้้้้้้้ …it’s an ก (Thai character ko kai) (U+0E01) followed by 20 copies of the Thai combining character … Read more

C# Sanitize File Name

To clean up a file name you could do this private static string MakeValidFileName( string name ) { string invalidChars = System.Text.RegularExpressions.Regex.Escape( new string( System.IO.Path.GetInvalidFileNameChars() ) ); string invalidRegStr = string.Format( @”([{0}]*\.+$)|([{0}]+)”, invalidChars ); return System.Text.RegularExpressions.Regex.Replace( name, invalidRegStr, “_” ); }

Catch paste input

OK, just bumped into the same issue.. I went around the long way $(‘input’).on(‘paste’, function () { var element = this; setTimeout(function () { var text = $(element).val(); // do something with text }, 100); }); Just a small timeout till .val() func can get populated. E.

Turn a string into a valid filename?

You can look at the Django framework for how they create a “slug” from arbitrary text. A slug is URL- and filename- friendly. The Django text utils define a function, slugify(), that’s probably the gold standard for this kind of thing. Essentially, their code is the following. import unicodedata import re def slugify(value, allow_unicode=False): “”” … Read more

tech