Frequently Asked Questions
Set up 2FA in RedwoodJS by first installing required dependencies like the AWS SDK for SNS and bcrypt. Then, modify your Prisma schema to include fields for phone numbers, 2FA status, OTP details, and update your database. Finally, configure environment variables for your AWS credentials and region in your .env file. Remember to apply database migrations after schema changes.
AWS SNS (Simple Notification Service) is used to deliver One-Time Passwords (OTPs) via SMS messages to users' registered phone numbers as part of the two-factor authentication process. This ensures secure access by verifying user identity.
bcrypt is essential for securely storing OTPs. It hashes the generated OTP codes before saving them to the database, preventing storage of sensitive information in plain text. This protects user accounts in case of a data breach.
Request production access for AWS SNS before deploying your RedwoodJS application to real users. New AWS accounts default to a sandbox environment, restricting SMS messages to verified numbers within your account. Production access enables you to send OTPs to any valid phone number.
Yes, you can customize the SMS sender ID using the AWS_SNS_SENDER_ID environment variable in your RedwoodJS app. However, using a custom sender ID often requires registering with authorities in specific countries to ensure compliance. If omitted, a generic number may be used.
Use Node.js's `crypto.randomInt` function within your RedwoodJS OTP service to generate cryptographically secure random numbers for your OTP codes. This method is preferred over `Math.random()` for enhanced security in sensitive operations.
dbAuth in RedwoodJS provides the primary authentication layer (username/password login). The OTP-based 2FA adds an additional security layer on top of dbAuth, triggered only after successful password authentication, if the user has 2FA enabled.
Implement robust rate limiting for OTP requests in RedwoodJS by integrating mechanisms like IP-based or user-based limits. You can utilize middleware or external stores like Redis with algorithms such as leaky bucket or token bucket, preventing abuse and ensuring the security of the OTP process.
Use the E.164 format (+15551234567) for storing and validating phone numbers in RedwoodJS 2FA. This international standard format is crucial for compatibility with AWS SNS and ensures accurate OTP delivery.
Verify OTP codes securely using `bcrypt.compare` to check the user-submitted code against the stored bcrypt hash of the OTP. This prevents direct comparison of plain text codes and protects against security vulnerabilities.
If a user exceeds the maximum OTP attempts (as defined by MAX_OTP_ATTEMPTS in your OTP service), their current OTP is cleared, requiring them to request a new one. This mitigates brute-force attacks.
Hashing is crucial for OTP security as it transforms the OTP into a unique, irreversible representation, preventing the storage of the actual OTP in the database. Using bcrypt for hashing adds a layer of protection against potential data breaches, ensuring that even if compromised, the OTPs remain unreadable.
Handle OTP expiry in RedwoodJS by setting an expiration time (`otpExpiresAt`) when generating the OTP. During verification, check if the current time is past the expiration; if so, invalidate the OTP, clear relevant fields, and prompt the user to request a new one.
Content Loading Error
We encountered an error while processing this content.