dovs36921 2016-12-29 17:10
浏览 51
已采纳

php-cordova:安全的后端文件

I am using cordova to create a android app and i am using php-mysql as backend.

I am fetching/sending data from database by ajax. As you know we can't fetch the data directly due to CORS issue. to fetch the data remotly we need to add header("Access-Control-Allow-Origin: *");

Problem is it makes my backend exposed. Because any one can try to fetch the data from backend. Which i don't want.

Please advise how can i make it secure.

Thanks

  • 写回答

1条回答 默认 最新

  • dpdp42233 2016-12-29 21:53
    关注

    You can remove header("Access-Control-Allow-Origin: *"); from your backend service.

    After that for your cordova application you need to install whitelist plugin and to config it.

    Add this in your config.xml:

    <access origin="*" />
    <allow-navigation href="*"/>
    

    Include Content-Security-Policy meta in your html page.

    <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data:">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献