dsvf46980 2011-10-31 16:44
浏览 242
已采纳

request_param在Smarty模板中转义

I've got a simple search script which returns results based on a query string from the URL:

$filter_query = request_param('query');
if ($filter_query) {
  $topic_filters['query'] = $filter_query;
  $smarty->assign('query', $filter_query);
}

However currently this is exposed to XSS and abuse as its not sanitising the input of 'query'.

Im using Smarty Templates, are there any inbuilt functions to do this automatically?

  • 写回答

2条回答 默认 最新

  • dqyq88053 2011-10-31 16:54
    关注

    Inside your Smarty template, use the escape modifier to escape the output against XSS attacks. By default it escapes & " ' < >. If you need additional entities encoded, use the :htmlall parameter to the escape modifier. (see the documentation)

    {* Inside your template... *}
    This is the value of {$query|escape}
    

    Otherwise you can escape it before assigning to Smarty with htmlspecialchars()

    // Or beforehand in PHP, which protects you from forgetting to do it in your template
    // if you use the same variable in many locations.
    $smarty->assign('query', htmlspecialchars($filter_query));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答