簡體   English   中英

使用Ajax提交表單是否安全?

[英]Would submitting a form using Ajax be secure?

所以我的表單是用html構建的,並在JS中驗證,它看起來像我想要的那樣。 現在顯然我將在服務器端使用PHP驗證輸入,但我想知道它是否足夠安全,使用Ajax提交表單然后在服務器端驗證,而不是使用'submit'類型提交表單按鈕和'動作'屬性。 基本上,使服務器端驗證依賴於JS提交它是否安全?

這是我的表格:

<form name="contactForm" id="contactForm"><!-- The form has no action attribute because its submitted via Ajax -->
<div id="inputsWrapper">
    <div>
        <label for="fullName">Your Name: <span class="required">(required)</span></label>
        <input type="text" name="fullName" id="fullName" title="First &amp; last name" value="First &amp; last name" maxlength="50" />
    </div>
    <div>
        <label for="email">Your E-mail: <span class="required">(required)</span></label>
        <input type="text" name="email" id="email" title="E-mail address" value="E-mail address" maxlength="500" />
    </div>
    <div>
        <label for="subject">In Regards To: <span class="required">(required)</span></label>
        <input type="text" name="subject" id="subject" title="Subject" value="Subject" maxlength="50"/>
    </div>
    <div>
        <label for="message">Your Message: <span class="required">(required)</span></label>
        <textarea name="message" id="message" title="Enter your message here" cols="40" rows="10">Enter your message here</textarea>
    </div>
</div> <!-- End inputsWrapper -->
<input type="button" name="sendBtn" id="sendBtn" value="Send Message" /><!-- This button has a listener assigned to it in JS and submits the form on click -->

單擊按鈕后,Ajax將通過POST將表單提交到我的PHP腳本,並返回有效與否。 這是否是一種安全的方式來做到這一點? 謝謝你的任何建議。

通過Ajax或通過瀏覽器默認表單發布行為發布它不會從安全角度來看有所不同。 請求將是常規HTTP POST / GET請求。

我想知道使用Ajax提交表單然后在服務器端進行驗證是否足夠安全,而不是使用“提交”類型按鈕和“操作”屬性提交表單。

是。 系統外部的輸入是從系統外部輸入的。

基本上,使服務器端驗證依賴於JS提交它是否安全?

您的JavaScript應該是不引人注目的並實現漸進增強

對於腳本的輸入應該是相同的,無論它是來自Ajax的常規表單提交(如果你使用像jQuery的序列化這樣很容易),所以你不應該讓服務器依賴於JS的回應。

表單提交和Ajax請求的處理方式的唯一區別應該是響應的格式。

無論哪種方式,進入系統的數據最終都在提交者的控制之下,因此您需要執行適當的健全性檢查並以任何方式轉義它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM