-
Notifications
You must be signed in to change notification settings - Fork 2
Caching tokens with redis & reset Password #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
45fbc7a
1c774c5
3ab007f
8dc8e9f
6be6860
739b39a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,5 +9,16 @@ | |||||||||||||||||||||||||
| "Microsoft.AspNetCore": "Warning" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| "ExpireTimes": { | ||||||||||||||||||||||||||
| "Jwt_Token_Exp":10, | ||||||||||||||||||||||||||
| "Refresh_Token_Exp":30 | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| "EmailOption": { | ||||||||||||||||||||||||||
| "client": "smtp.gmail.com", | ||||||||||||||||||||||||||
| "password": "password", | ||||||||||||||||||||||||||
| "from": "email", | ||||||||||||||||||||||||||
| "port":567 | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
|
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SMTP port is likely wrong; fix 567 → 587 (or 465 for SSL). Also avoid storing plaintext passwords. Apply: "EmailOption": {
"client": "smtp.gmail.com",
- "password": "password",
+ "password": "",
"from": "email",
- "port":567
+ "port": 587
},Consider removing EmailOption from source-controlled appsettings.json entirely and sourcing via appsettings.Development.json + secrets. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| "ClientUrYour App Namel": " http://localhost:5180", | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo and leading space in client URL key/value. Apply: -"ClientUrYour App Namel": " http://localhost:5180",
+"ClientUrl": "http://localhost:5180",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| "AllowedHosts": "*" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| namespace AskFm.BLL.DTO; | ||
|
|
||
| public class EmailSettings | ||
| { | ||
| [Required, EmailAddress] | ||
| public string From {get; set;} | ||
| [Required] | ||
| public string Client {get; set;} | ||
| [Required] | ||
| public string Password {get;set;} | ||
| [Range(1, 65535)] | ||
| public int Port {get; set; } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,11 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
|
|
||
| namespace AskFm.DAL.Models; | ||
| [Owned] | ||
| public class RefreshToken | ||
| namespace AskFm.BLL.DTO; | ||
| public class RefreshTokenDto | ||
| { | ||
| public string Token { get; set; } | ||
| public DateTime ExpireOn { get; set; } | ||
| public bool IsExpired => DateTime.Now >= ExpireOn; | ||
| public DateTime? RevokedOn { get; set; } | ||
| public bool IsActive => RevokedOn == null && !IsExpired; | ||
|
|
||
| public int ExpireAfter { get; set; } | ||
| public DateTime CreatedOn { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,6 @@ public class AuthResponseDTO | |
| { | ||
| public bool IsAuthenticated { get; set; } | ||
| public string Token { get; set; } | ||
| public RefreshToken RefreshToken { get; set; } | ||
| public RefreshTokenDto RefreshToken { get; set; } | ||
| public ReadUserDTO User { get; set; } | ||
|
Comment on lines
8
to
10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t return refresh tokens in API payloads. Prefer HttpOnly, Secure cookies; if you must keep the property, mark it ignored for serialization. using AskFm.DAL.Models;
namespace AskFm.BLL.DTO.UserDTOs;
public class AuthResponseDTO
{
public bool IsAuthenticated { get; set; }
public string Token { get; set; }
- public RefreshTokenDto RefreshToken { get; set; }
+ [JsonIgnore] // avoid exposing via JSON
+ public RefreshTokenDto RefreshToken { get; set; }
public ReadUserDTO User { get; set; }
}Add if not present: using System.Text.Json.Serialization;🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| namespace AskFm.BLL.DTO.UserDTOs; | ||
|
|
||
| public class ForgotPasswordDto | ||
| { | ||
| [Required] | ||
| [EmailAddress] | ||
| public string Email { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| namespace AskFm.BLL.DTO.UserDTOs; | ||
|
|
||
| public class ResetPasswordDto | ||
| { | ||
| [Required] | ||
| [EmailAddress] | ||
| public string Email { get; set; } | ||
|
|
||
| [Required] | ||
| public string Token { get; set; } | ||
|
|
||
| [Required] | ||
| public string NewPassword { get; set; } | ||
|
|
||
| [Required] | ||
| [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] | ||
| public string ConfirmPassword { get; set; } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Password reset endpoint lacks rate limiting
The forgot-password endpoint is vulnerable to abuse without rate limiting. Attackers could spam users with reset emails.
Consider implementing rate limiting at the API level or tracking reset attempts per email address in Redis with a time window.
🤖 Prompt for AI Agents