Files
yale-user-access/packages/backend/Models/ApiResponse.cs
T
LiamPietralla d0425c8cb2 Harden backend auth, validation and error handling
- Rate limit login (5 attempts/min per IP) with a JSON 429 response
- Constant-time password comparison; refuse login if no password is configured
- Explicit SameSite=Strict auth cookie; log failed logins with client IP
- Stop logging door codes (update log lines and the SMS body)
- Replace per-action try/catch -> 400 with a global exception handler (JSON 500)
- Return proper statuses: 404 for missing person, 502 for failed lock writes
- Validate codes as ASCII digits only (int.TryParse accepted +/-/whitespace)
- Validate person name and E.164 phone number; reject sending an unset code
- Rename TwiloOptions -> TwilioOptions and fix message typos
- Expose Program for integration tests
2026-11-16 12:23:31 +11:00

30 lines
745 B
C#

namespace YaleAccess.Models
{
public class ApiResponse
{
public bool Success { get; set; }
public string? Error { get; set; }
public object? Data { get; set; }
/// <summary>
/// If passing in data only then the response is successful
/// </summary>
/// <param name="data"></param>
public ApiResponse(object data)
{
Success = true;
Data = data;
}
/// <summary>
/// If passing in an error then the response is not successful
/// </summary>
/// <param name="error"></param>
public ApiResponse(string error)
{
Success = false;
Error = error;
}
}
}