Example #1
0
/**
 * Checks for <script> embedding and any double-URL-encoded data
 * 
 * @return bool
 */
function checkUserInput($input)
{
    $scripting = '/(%3C|<|&lt;|&#60;)\\s*(script|\\?)/iU';
    $asciiChars = '/%(0|1)(\\d|[a-f])/i';
    // Call recursively if input is an array
    if (is_array($input)) {
        foreach ($input as $input_val) {
            if (!checkUserInput($input_val)) {
                return FALSE;
            }
        }
        return TRUE;
    } else {
        // Decoding input once is ok
        $decodedInput = rawurldecode($input);
        // Check for any script tags or any remaining URL encoded characters
        if (preg_match($scripting, $decodedInput) || preg_match($asciiChars, $decodedInput)) {
            return FALSE;
        }
        return TRUE;
    }
}
Example #2
0
    }
    if ($interaction == "autosave") {
        // JSON-String in Datei schreiben
        $file = $dbPath . $sketchName . '_autosave.txt';
        $fp = fopen($file, 'w');
        fwrite($fp, json_encode($checkedInput));
        fclose($fp);
        $infoMessage[] = "Info: Der JSON-String wurde in die Datei " . $sketchName . "_autosave.txt zwischengespeichert.";
    }
    if ($interaction == "load") {
        $file = $dbPath . $sketchName . '.txt';
        if (is_file($file)) {
            $output = json_decode(file_get_contents($file));
            // Hier sollte nochmal die Datei auf Fehler oder Code Injection
            // geprüft werden
            $checkedOutput = checkUserInput($output);
            $infoMessage[] = "Info: Die Datei wurde geladen.";
            // print_r(json_encode($obj, JSON_FORCE_OBJECT));
        } else {
            $infoMessage[] = "Fehler: Die Datei konnte nicht gefunden werden.";
        }
    }
    if ($interaction == "import") {
        $infoMessage[] = "Info: Die Importfunktion ist noch nicht verfügbar.";
    }
} else {
    $infoMessage[] = "Fehler: Die Interaktion ist nicht erlaubt.";
}
// Fehlermeldung als JSON-String zurückgeben
if (!empty($infoMessage)) {
    $checkedOutput->message = $infoMessage;