標籤:秘密 new 排序 協議 價格 代碼 請求 index.php 判斷
https://segmentfault.com/q/1010000005618139
vue ajax擷取資料的時候,如何保證傳遞參數的安全或者說如何保護api的安全
點擊提交,發送請求。
但是api:123用於加密的參數,直接暴露了。右鍵原始碼就可以看到
<body><div class="row"> <div class="col-md-4 col-md-offset-4"> <table class="table table-bordered" id="content"> <tr> <td> 商品分類 </td> <td> <select name="cid" v-model="cid"> <template v-for="vo in goodscategory"> <option v-bind:value="vo.goodscategory_id">{{vo.goodscategory_name}}</option> </template> </select> {{cid}} </td> </tr> <tr> <td style="width: 30%"> 商品名稱 </td> <td> <input type="text" name="name" v-model="goodsname" value=""/> <span>{{ goodsname }}</span> </td> </tr> <tr> <td> 排序 </td> <td> <input type="text" name="sort" v-model="sort"/> {{sort}} </td> </tr> <tr> <td> 價格 </td> <td> <input type="text" v-model="price"/> {{price}} </td> </tr> <tr> <td> 商品描述 </td> <td> <textarea name="desc" id="" cols="30" rows="5" v-model="desc"></textarea> {{desc}} </td> </tr> <tr> <td colspan="2"> <button type="button" v-on:click="submit">提交</button> </td> </tr> </table> </div></div><script type="text/javascript"> var vm = new Vue({ el:"#content", data: { cid:0, goodsname:"", sort:0, price:0, desc:"", goodscategory:[] }, methods: { submit: function () { this.$http({ url: ‘http://localhost/wang/index.php/Admin/Goods/createProcess‘, method: ‘POST‘, emulateJSON: true, data: { cid: this.cid, name: this.goodsname, sort: this.sort, price: this.price, desc: this.desc } }).then(function(response) { console.log(response.data); }, function(response) { }); } }, ready: function() { var self = this; this.$http({url: ‘http://localhost/wang/index.php/Home/Vue/goodscategory‘, method: ‘POST‘}).then(function (response) { self.$set(‘goodscategory‘, response.data) }, function (response) { // error callback }); } })</script>
解決方案:
1.介面服務方輸入控制
2.參數合法性校正
3.HTTPS
4.CSRFToken安全性校正
這對使用者是透明的,防範思路:
1.服務端CSRFToken校正
2.refer校正
3.同一使用者的頻度控制
輸出響應前服務端對SessionID混淆首碼並加密(MD5),埋點在HTML隱藏<Input />,所有請求將此欄位發送給服務端,校正是否相等
判斷$_REQUEST[‘Referer‘],判斷這個欄位是不是為空白或者不是你希望的網域名稱 二
這類查看資料的api,有什麼秘密可言嗎?如果真有秘密,那應該在api鑒權上下功夫,譬如要求訪問這個api的人必須登入啊,或者有相應許可權啊什麼的。
否則如果僅僅是福士資料,本來也是給人看的,那能防得住嗎?
還有一點你沒搞清楚,資訊安全重點在資訊,但你理解成擷取資訊的渠道了。
Api就算防,也不是防止別人知道你的api,而且防止別人非法通過你的api擷取裡面的資料
那麼vue這種項目,用session還是cookie儲存使用者狀態。
https是在什麼時候加密資料
首先,session
是存在於服務端的儲存使用者狀態的東西。cookie
是在用戶端儲存資料的東西。二者完全不是一回事。
但通常我們配合使用,在用戶端用cookie
儲存一個sessionID
,使用者每次發請求到後端都帶著這個sessionID
,後端接收到請求後根據這個sessionID
再從不管緩衝也好、memcached
之類的緩衝工具也好裡面拿出對應的session
資料使用。
https
是協議層的東西,通常公司的營運、it工程師搞定,當然如果你確實需要瞭解,可以網上查資料
vue ajax擷取資料的時候,如何保證傳遞參數的安全或者說如何保護api的安全