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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘