|
| 1 | +// Quick manual security check for password exposure |
| 2 | +const axios = require('axios'); |
| 3 | + |
| 4 | +const API_BASE_URL = 'http://localhost:3001'; |
| 5 | + |
| 6 | +async function quickSecurityCheck() { |
| 7 | + console.log("🔍 Quick Security Check - Testing Password Exposure Prevention\n"); |
| 8 | + |
| 9 | + try { |
| 10 | + // 1. Create a test user |
| 11 | + console.log("1. Creating test user..."); |
| 12 | + const createResponse = await axios.post(`${API_BASE_URL}/api/users`, { |
| 13 | + email: 'security-test@example.com', |
| 14 | + password: 'secretpassword123', |
| 15 | + role: 'user' |
| 16 | + }); |
| 17 | + |
| 18 | + console.log(" ✅ User created successfully"); |
| 19 | + console.log(" �� Response data:", JSON.stringify(createResponse.data, null, 2)); |
| 20 | + |
| 21 | + // Check if password is in response |
| 22 | + if (createResponse.data.password) { |
| 23 | + console.log(" ❌ SECURITY ISSUE: Password found in create response!"); |
| 24 | + return; |
| 25 | + } else { |
| 26 | + console.log(" ✅ Password correctly excluded from create response"); |
| 27 | + } |
| 28 | + |
| 29 | + const userId = createResponse.data.id; |
| 30 | + |
| 31 | + // 2. Get the user by ID |
| 32 | + console.log("\n2. Getting user by ID..."); |
| 33 | + const getResponse = await axios.get(`${API_BASE_URL}/api/users/${userId}`); |
| 34 | + |
| 35 | + console.log(" 📋 Response data:", JSON.stringify(getResponse.data, null, 2)); |
| 36 | + |
| 37 | + if (getResponse.data.password) { |
| 38 | + console.log(" ❌ SECURITY ISSUE: Password found in get response!"); |
| 39 | + return; |
| 40 | + } else { |
| 41 | + console.log(" ✅ Password correctly excluded from get response"); |
| 42 | + } |
| 43 | + |
| 44 | + // 3. Get user by email |
| 45 | + console.log("\n3. Getting user by email..."); |
| 46 | + const emailResponse = await axios.get(`${API_BASE_URL}/api/users/email/security-test@example.com`); |
| 47 | + |
| 48 | + console.log(" 📋 Response data:", JSON.stringify(emailResponse.data, null, 2)); |
| 49 | + |
| 50 | + if (emailResponse.data.password) { |
| 51 | + console.log(" ❌ SECURITY ISSUE: Password found in email lookup response!"); |
| 52 | + return; |
| 53 | + } else { |
| 54 | + console.log(" ✅ Password correctly excluded from email lookup response"); |
| 55 | + } |
| 56 | + |
| 57 | + // 4. Get all users |
| 58 | + console.log("\n4. Getting all users..."); |
| 59 | + const allUsersResponse = await axios.get(`${API_BASE_URL}/api/users`); |
| 60 | + |
| 61 | + console.log(` 📋 Retrieved ${allUsersResponse.data.length} users`); |
| 62 | + |
| 63 | + // Check if any user has password field |
| 64 | + const hasPasswordInAnyUser = allUsersResponse.data.some(user => user.password); |
| 65 | + if (hasPasswordInAnyUser) { |
| 66 | + console.log(" ❌ SECURITY ISSUE: Password found in get all users response!"); |
| 67 | + return; |
| 68 | + } else { |
| 69 | + console.log(" ✅ Password correctly excluded from all users response"); |
| 70 | + } |
| 71 | + |
| 72 | + // 5. Update user |
| 73 | + console.log("\n5. Updating user..."); |
| 74 | + const updateResponse = await axios.put(`${API_BASE_URL}/api/users/${userId}`, { |
| 75 | + email: 'updated-security-test@example.com', |
| 76 | + password: 'newsecretpassword456', |
| 77 | + role: 'admin' |
| 78 | + }); |
| 79 | + |
| 80 | + console.log(" �� Response data:", JSON.stringify(updateResponse.data, null, 2)); |
| 81 | + |
| 82 | + if (updateResponse.data.password) { |
| 83 | + console.log(" ❌ SECURITY ISSUE: Password found in update response!"); |
| 84 | + return; |
| 85 | + } else { |
| 86 | + console.log(" ✅ Password correctly excluded from update response"); |
| 87 | + } |
| 88 | + |
| 89 | + // Clean up |
| 90 | + console.log("\n6. Cleaning up test user..."); |
| 91 | + await axios.delete(`${API_BASE_URL}/api/users/${userId}`); |
| 92 | + console.log(" ✅ Test user deleted"); |
| 93 | + |
| 94 | + console.log("\n🎉 ALL SECURITY CHECKS PASSED!"); |
| 95 | + console.log("🔒 Password fields are correctly excluded from all API responses!"); |
| 96 | + |
| 97 | + } catch (error) { |
| 98 | + console.error("❌ Test failed:", error.message); |
| 99 | + if (error.response) { |
| 100 | + console.error(" Response status:", error.response.status); |
| 101 | + console.error(" Response data:", error.response.data); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +// Run the check |
| 107 | +quickSecurityCheck(); |
0 commit comments