feat: Implement password masking and encryption in data services
- Added a new function `maskPasswordColumns` to mask password fields in data responses, ensuring sensitive information is not exposed. - Integrated password handling in `DynamicFormService` to encrypt new passwords and maintain existing ones when empty values are provided. - Enhanced logging for better tracking of password field updates and masking failures, improving overall security and debugging capabilities.
This commit is contained in:
@@ -2,6 +2,7 @@ import { query, queryOne, transaction, getPool } from "../database/db";
|
||||
import { EventTriggerService } from "./eventTriggerService";
|
||||
import { DataflowControlService } from "./dataflowControlService";
|
||||
import tableCategoryValueService from "./tableCategoryValueService";
|
||||
import { PasswordUtils } from "../utils/passwordUtils";
|
||||
|
||||
export interface FormDataResult {
|
||||
id: number;
|
||||
@@ -859,6 +860,33 @@ export class DynamicFormService {
|
||||
}
|
||||
}
|
||||
|
||||
// 비밀번호(password) 타입 컬럼 처리
|
||||
// - 빈 값이면 변경 목록에서 제거 (기존 비밀번호 유지)
|
||||
// - 값이 있으면 암호화 후 저장
|
||||
try {
|
||||
const passwordCols = await query<{ column_name: string }>(
|
||||
`SELECT DISTINCT column_name FROM table_type_columns
|
||||
WHERE table_name = $1 AND input_type = 'password'`,
|
||||
[tableName]
|
||||
);
|
||||
for (const { column_name } of passwordCols) {
|
||||
if (column_name in changedFields) {
|
||||
const pwValue = changedFields[column_name];
|
||||
if (!pwValue || pwValue === "") {
|
||||
// 빈 값 → 기존 비밀번호 유지 (변경 목록에서 제거)
|
||||
delete changedFields[column_name];
|
||||
console.log(`🔐 비밀번호 필드 ${column_name}: 빈 값이므로 업데이트 스킵 (기존 유지)`);
|
||||
} else {
|
||||
// 값 있음 → 암호화하여 저장
|
||||
changedFields[column_name] = PasswordUtils.encrypt(pwValue);
|
||||
console.log(`🔐 비밀번호 필드 ${column_name}: 새 비밀번호 암호화 완료`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (pwError) {
|
||||
console.warn("⚠️ 비밀번호 컬럼 처리 중 오류:", pwError);
|
||||
}
|
||||
|
||||
// 변경된 필드가 없으면 업데이트 건너뛰기
|
||||
if (Object.keys(changedFields).length === 0) {
|
||||
console.log("📋 변경된 필드가 없습니다. 업데이트를 건너뜁니다.");
|
||||
|
||||
Reference in New Issue
Block a user