Security की Best Practices
कुछ habits, जैसे input validate करना और packages updated रखना, ज़्यादातर common attacks block करती हैं।
In this page:
Security Best Practices
सारा input validate और sanitize करें, parameterized queries इस्तेमाल करें, passwords hash करें, helmet से security headers set करें, HTTPS इस्तेमाल करें, और npm audit से dependencies updated रखें।
Request sizes limit करें, eval से बचें, और कभी stack traces expose न करें। Tokens और processes के लिए least privilege follow करें।
Note:
नियमित रूप से npm audit चलाएँ और vulnerable packages update करें।
उदाहरण: Security best practices
function escapeHtml(s) {
return s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
}
const userInput = '<script>alert("x")</script>';
console.log(escapeHtml(userInput));
const id = "1; DROP TABLE users";
console.log("valid id:", /^\d+$/.test(id));
// Output:
// <script>alert("x")</script>
// valid id: false
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- user input पर trust करना
- strings से SQL या shell commands बनाना
- npm audit warnings ignore करना
चैप्टर सारांश
- सारा input validate करें
- Parameterized queries इस्तेमाल करें
- helmet से security headers set करें
- Dependencies audit और update करें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: