duanchao1002 2016-05-20 01:11
浏览 64
已采纳

如果我不写入数据库,应该如何清理用户输入?

I have a simple web page with a textarea that when multiple lines of tab delineated text is input, a php script processes the text and outputs the resulting string as a text file for the user to download.

The page itself is nothing more than a textarea and a submit button that posts to itself. If post data is received, it basically creates an array of the lines of text in the textbox (using explode(" ",$text), then loops through each line and creates an array of each section of text in the line (using explode("\t",$text). Finally, it takes each element in the array and constructs a string with it. The only other php function used in the script is the date function and the strtotime function along with a couple of foreach statements.

When the string is complete, the string is sent to the browser as a text file using a few header() functions (Content-Disposition: attachment; , Content-Type: , etc). So, assuming $str is the string, this is how it is sent to the browser:

header('Content-Disposition: attachment; filename="file.txt"')
header('Content-Type: text/plain'); 
header('Content-Length: ' . strlen($str));
echo $str;
exit();

For example, suppose the text supplied is this (pretend the spaces between text are tabs)

John    Smith    Freshman
Jane    Doe      Sophomore

Then the script creates a string as follows:

Student:
firstname:John
lastname:Smith
Year:Freshman
EndStudent
Student:
firstname:Jane
lastname:Doe
Year:Sophomore
EndStudent

And that script is sent to the browser as a text/plain file.

The script works fine, the output file is correct. My question is what kind of security holes am I leaving myself open and is it possible to close them ( and how to close them ). I would like the page to be public.

  • 写回答

1条回答 默认 最新

  • duanjie3267 2016-05-20 01:27
    关注

    Since you're never interpreting the text and execute any code in response to instructions found within the text, there's absolutely no security concern here.

    The only thing you'd need to be careful about is the use of special characters: your output uses specific characters with a certain meaning, namely . If your input contained a , and you're passing that trough to the output as is, would your output's meaning change? Perhaps you need to escape or remove any found in the input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型