Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/src/api/controllers/controllerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type SSLCheckerType = typeof sslChecker;
export const fetchMonitorCertificate = async (checker: SSLCheckerType, monitor: Monitor): Promise<SSLDetails> => {
const monitorUrl = new URL(monitor.url);
const hostname = monitorUrl.hostname;
const cert = await checker(hostname);
const port = monitorUrl.port ? parseInt(monitorUrl.port, 10) : undefined;
const cert = await checker(hostname, { ...(port ? { port } : {}) });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty convoluted way of expressing that port should not be added here if not specificed.

checker(hostname, port ? { port } : undefined)

seems clearer to me 🤔

if (cert?.validTo === null || cert?.validTo === undefined) {
throw new Error("Certificate not found");
}
Expand Down
9 changes: 7 additions & 2 deletions server/src/domain/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,17 @@ export class UserService implements IUserService {

loginUser = async (email: string, password: string) => {
// Check if user exists
const user = await this.usersRepository.findByEmail(email);
let user;
try {
user = await this.usersRepository.findByEmail(email);
} catch {
throw new AppError({ message: "Incorrect email or password", service: SERVICE_NAME, status: 401 });
}
Comment on lines +224 to +228

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't resolve the enumeration problem. Attackers can still determine if they have found a correct email credential, as bcrypt is still awaited after the user lookup.

If you want to fully resolve the enumeration issue then a dummy value needs to be hashed on the user not found path.

Additionally, this catch block is too broad, it classifies all errors thrown by the repository as email/password errors. This should be narrowed appropriately.

// Compare password
const match = await bcrypt.compare(password, user.password);

if (match !== true) {
throw new AppError({ message: "Incorrect password", service: SERVICE_NAME, status: 401 });
throw new AppError({ message: "Incorrect email or password", service: SERVICE_NAME, status: 401 });
}

// Remove password from user object. Should this be abstracted to DB layer?
Expand Down
2 changes: 1 addition & 1 deletion server/test/unit/services/userService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ describe("UserService", () => {
const hashed = bcrypt.hashSync("correct-password", 10);
(usersRepository.findByEmail as jest.Mock).mockResolvedValue(makeUser({ password: hashed }));

await expect(service.loginUser("test@example.com", "wrong-password")).rejects.toThrow("Incorrect password");
await expect(service.loginUser("test@example.com", "wrong-password")).rejects.toThrow("Incorrect email or password");
});
});

Expand Down
Loading