메일 인증 대신 휴대폰 본인확인을 쓸 수 있게 하는 플러그인을 추가한다. 가입·비밀번호 재설정·성인인증 등 코어 IDV 가 강제하는 모든 지점에서 동작하며, 테스트 모드로 계약 없이 전 흐름을 확인할 수 있다. 구현·검수 과정에서 드러난 저장소 전역 결함을 함께 처리했다. - 외래키 컬럼의 한국어 comment 가 방출되지 않던 문제 (소스 38건 교정 + 기설치본 백필 업그레이드 스텝 7종). ->comment 를 ->constrained 뒤에 체인하면 예외 없이 통과하면서 comment 가 조용히 사라진다 - 로케일 전환 후 확장 액션 핸들러가 소실되던 문제 (플러그인 3종에 재등록 진입점 노출) - 본인인증 상태 폴링 응답이 누적 시도 횟수를 함께 내보내던 문제 - 인증 안내 문구와 실제 진행 방식의 폭 경계 불일치 (768~1023px). 엔진과 같은 값을 같은 방법으로 읽도록 교정 - transition_overlay_target 이 replace 없이 무효이던 관리자 목록 40곳. 로딩 표시가 나오지 않아도 경고가 남지 않아 화면을 봐야만 알 수 있었다 두 인증 플러그인의 코어 최소 요구 버전을 7.0.6 으로 올린다. 운영 모드 자격증명 필수 검사가 7.0.6 의 설정 저장 검증 표면에 의존하며, 그보다 낮은 코어에서는 그 검사가 조용히 통과해 빈 자격증명으로 저장할 수 있었다. 재발 차단으로 정적 검사 룰 4종을 신설하고, 검사 도구가 미커밋 신규 확장을 "검사 파일 0" 으로 통과시키던 사각을 함께 막았다.
285 lines
12 KiB
TypeScript
285 lines
12 KiB
TypeScript
/**
|
|
* sirsoft-gdpr 플러그인 진입점
|
|
*
|
|
* 페이지 로드 시 자동 부트스트랩:
|
|
*
|
|
* 0. 사전 차단 즉시 등록 (preblocker) — settings fetch 기다리지 않고
|
|
* window.G7Config.plugins['sirsoft-gdpr'].blocked_domains 를 동기 사용하여
|
|
* HTMLScriptElement.prototype.src setter 가로채기. 보수적 동의 (necessary 만)
|
|
* 상태로 진입하여 settings/consent 응답 지연 동안 추적 스크립트가 외부 로드되는
|
|
* race condition 방지.
|
|
* 1. Phase 2 1st-party storage/cookie 인터셉터 즉시 등록 — strictly necessary
|
|
* allowlist 외 모든 비-필수 저장을 동의 시까지 차단 (EDPB Guidelines 2/2023 §16).
|
|
* user-initiated 면제 (WP29 §3.6) 는 항상 활성.
|
|
* 2. 공개 설정 페치 (banner_enabled / cookie_policy_version / blocked_domains)
|
|
* 3. 자동 차단 엔진 (MutationObserver 백업 라인) 시작 — banner_enabled=true 시
|
|
* 4. 현재 방문자의 카테고리별 동의 상태 페치 후 preblocker + blocker + interceptor 동기화
|
|
* 5. 부팅 시점 functional 미동의면 cleanup 호출 (allowlist 외 모든 storage/cookie 파기, EDPB §117)
|
|
* 6. ActionDispatcher 에 `sirsoft-gdpr.syncConsent` 핸들러 등록 — 레이아웃의 동의 저장
|
|
* onSuccess 에서 호출하여 두 차단 엔진 + 인터셉터 동기화 + 필요 시 cleanup
|
|
*
|
|
* 동의 SSoT 는 서버 DB. 배너 표시/저장은 cookie_banner.json 레이아웃이 단독 처리하며,
|
|
* 차단 엔진 + 인터셉터는 `sirsoft-gdpr.syncConsent` 핸들러로 동기화.
|
|
*
|
|
* @module sirsoft-gdpr/index
|
|
*/
|
|
|
|
import '../css/banner.css';
|
|
import { startBlocker, setCurrentConsent, setBlockedDomains } from './blocker';
|
|
import {
|
|
installCookieInterceptor,
|
|
updateCookieInterceptorConfig,
|
|
DEFAULT_NECESSARY_COOKIE_ALLOWLIST,
|
|
} from './cookieInterceptor';
|
|
import { cleanupFunctionalArtifacts } from './functionalCleaner';
|
|
import { fetchPublicSettings, fetchConsentSnapshot } from './layouts';
|
|
import {
|
|
installPreblocker,
|
|
updatePreblockerConfig,
|
|
restorePreblockedCategory,
|
|
type PreblockerConfig,
|
|
} from './preblocker';
|
|
import {
|
|
installStorageInterceptor,
|
|
updateStorageInterceptorConfig,
|
|
DEFAULT_NECESSARY_ALLOWLIST,
|
|
} from './storageInterceptor';
|
|
import { installUserInitiatedTracker } from './userInitiatedTracker';
|
|
|
|
const PLUGIN_IDENTIFIER = 'sirsoft-gdpr';
|
|
|
|
interface ActionDispatcher {
|
|
registerHandler: (name: string, handler: (...args: unknown[]) => unknown) => void;
|
|
}
|
|
|
|
interface G7Config {
|
|
plugins?: Record<string, Record<string, unknown>>;
|
|
}
|
|
|
|
/**
|
|
* G7Config 인라인 페이로드에서 GDPR 차단 카탈로그 즉시 조회.
|
|
*
|
|
* @return 카테고리 → 도메인 패턴 배열
|
|
*/
|
|
function readInlineBlockedDomains(): Record<string, readonly string[]> {
|
|
if (typeof window === 'undefined') return {};
|
|
const config = (window as unknown as { G7Config?: G7Config }).G7Config;
|
|
const pluginConfig = config?.plugins?.[PLUGIN_IDENTIFIER];
|
|
const raw = pluginConfig?.blocked_domains;
|
|
if (raw === undefined || raw === null || typeof raw !== 'object') return {};
|
|
|
|
const normalized: Record<string, readonly string[]> = {};
|
|
for (const [category, domains] of Object.entries(raw as Record<string, unknown>)) {
|
|
if (!Array.isArray(domains)) continue;
|
|
const strs = domains.filter((d): d is string => typeof d === 'string' && d !== '');
|
|
if (strs.length > 0) normalized[category] = strs;
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
/**
|
|
* banner_enabled 도 G7Config 페이로드에 인라인 — 페이지 진입 즉시 사용 가능.
|
|
*
|
|
* @return banner_enabled boolean
|
|
*/
|
|
function readInlineBannerEnabled(): boolean {
|
|
if (typeof window === 'undefined') return false;
|
|
const config = (window as unknown as { G7Config?: G7Config }).G7Config;
|
|
const pluginConfig = config?.plugins?.[PLUGIN_IDENTIFIER];
|
|
return pluginConfig?.banner_enabled === true;
|
|
}
|
|
|
|
/**
|
|
* G7Core.getActionDispatcher() 가 준비될 때까지 대기 후 핸들러 등록.
|
|
*
|
|
* 모듈/플러그인 에셋 로딩 순서에 따라 ActionDispatcher 가 아직 초기화 안 됐을 수
|
|
* 있으므로 setTimeout 으로 polling. module-assets.md 의 권장 패턴.
|
|
*/
|
|
function registerSyncHandler(): void {
|
|
const dispatcher = (
|
|
window as unknown as { G7Core?: { getActionDispatcher?: () => ActionDispatcher | undefined } }
|
|
).G7Core?.getActionDispatcher?.();
|
|
|
|
if (!dispatcher) {
|
|
setTimeout(registerSyncHandler, 100);
|
|
return;
|
|
}
|
|
|
|
// sirsoft-gdpr.syncConsent — 동의 저장 직후 차단 엔진 + 인터셉터 동기화
|
|
dispatcher.registerHandler(`${PLUGIN_IDENTIFIER}.syncConsent`, async () => {
|
|
const snapshot = await fetchConsentSnapshot();
|
|
if (snapshot === null) return;
|
|
|
|
const functionalConsented = !snapshot.needs_renewal && snapshot.categories.functional === true;
|
|
|
|
// 1. blocker.ts (MutationObserver 백업 라인) 동기화 — rescan 으로 placeholder 복원
|
|
setCurrentConsent({ categories: snapshot.categories, needs_renewal: snapshot.needs_renewal });
|
|
|
|
// 2. preblocker (1차 라인) 동기화 — 새 차단 판정에 즉시 반영
|
|
const blockedDomains = readInlineBlockedDomains();
|
|
updatePreblockerConfig({
|
|
blockedDomains,
|
|
consent: snapshot.categories,
|
|
needs_renewal: snapshot.needs_renewal,
|
|
});
|
|
|
|
// 3. Phase 2: storage / cookie 인터셉터 동기화
|
|
updateStorageInterceptorConfig({
|
|
functionalConsented,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_ALLOWLIST,
|
|
});
|
|
updateCookieInterceptorConfig({
|
|
functionalConsented,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_COOKIE_ALLOWLIST,
|
|
});
|
|
|
|
// 4. EDPB §117: 동의 철회 즉시 파기 — strictly necessary allowlist 외 모든 storage/cookie cleanup.
|
|
if (!functionalConsented) {
|
|
cleanupFunctionalArtifacts();
|
|
}
|
|
|
|
// 5. 동의 받은 카테고리의 preblocker 차단 요소 복원 (단, needs_renewal=true 면 복원 안 함)
|
|
if (!snapshot.needs_renewal) {
|
|
for (const [category, allowed] of Object.entries(snapshot.categories)) {
|
|
if (allowed === true && category !== 'necessary') {
|
|
restorePreblockedCategory(category);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 부트스트랩 — DOMContentLoaded 또는 즉시 실행.
|
|
*/
|
|
async function bootstrap(): Promise<void> {
|
|
if (typeof window === 'undefined') return;
|
|
|
|
// 핸들러 등록은 banner_enabled 활성 여부와 무관하게 항상 수행.
|
|
registerSyncHandler();
|
|
|
|
// 0. preblocker + 1st-party 인터셉터 즉시 등록 (banner_enabled=true 시) — settings fetch 기다리지 않음.
|
|
// G7Config 인라인 페이로드 (HTML 응답에 동기 포함) 로 즉시 카탈로그 사용 가능.
|
|
// 보수적 동의 상태 (necessary 만) 로 진입 — settings/consent fetch 완료 후 보강.
|
|
const inlineBannerEnabled = readInlineBannerEnabled();
|
|
if (inlineBannerEnabled) {
|
|
const inlineDomains = readInlineBlockedDomains();
|
|
installPreblocker({
|
|
blockedDomains: inlineDomains,
|
|
consent: { necessary: true },
|
|
});
|
|
|
|
// Phase 2: functional 1st-party storage 게이팅 (EDPB Guidelines 2/2023 §16).
|
|
// - userInitiatedTracker: 사용자 인터랙션 시각 기록 (WP29 §3.6 면제 판정용, 항상 활성)
|
|
// - storageInterceptor: localStorage / sessionStorage 신규 쓰기 가로채기
|
|
// - cookieInterceptor: document.cookie 신규 쓰기 가로채기
|
|
// 모두 strictly necessary allowlist (코드 상수) 외 미동의 + 비-사용자 쓰기는 차단.
|
|
installUserInitiatedTracker();
|
|
installStorageInterceptor({
|
|
functionalConsented: false,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_ALLOWLIST,
|
|
});
|
|
installCookieInterceptor({
|
|
functionalConsented: false,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_COOKIE_ALLOWLIST,
|
|
});
|
|
}
|
|
|
|
// 1. 공개 설정 fetch — banner_enabled / blocked_domains 의 SSoT 확정값 조회.
|
|
// G7Config 인라인은 *페이지 진입 시 스냅샷* 이라 SPA 라우트 이동 후 변경 가능성 대비.
|
|
const settings = await fetchPublicSettings();
|
|
if (!settings) {
|
|
return;
|
|
}
|
|
|
|
const bannerEnabled = settings.banner_enabled === true;
|
|
if (!bannerEnabled) {
|
|
return;
|
|
}
|
|
|
|
// 도메인 기반 차단 목록 주입 (blocker.ts 백업 라인) — 운영자 입력 도메인만 사용.
|
|
const customDomains = (settings.blocked_domains as Record<string, string[]> | undefined) ?? {};
|
|
setBlockedDomains(customDomains);
|
|
|
|
// preblocker 카탈로그도 보강 (인라인 페이로드와 응답 일치성 확인 + 누락 시 보강)
|
|
const preblockerConfig: PreblockerConfig = {
|
|
blockedDomains: customDomains,
|
|
consent: { necessary: true },
|
|
};
|
|
updatePreblockerConfig(preblockerConfig);
|
|
|
|
startBlocker();
|
|
|
|
// 2. 현재 동의 상태 페치 후 두 엔진 + 인터셉터 동기화 + 복원
|
|
// needs_renewal=true 면 옛 동의가 신정책에 그대로 쓰이는 상태 → 복원 안 함 (보수적 차단 유지)
|
|
const snapshot = await fetchConsentSnapshot();
|
|
const functionalConsented =
|
|
snapshot !== null && !snapshot.needs_renewal && snapshot.categories.functional === true;
|
|
|
|
// Phase 2: storage / cookie 인터셉터 설정 갱신 (functional 동의 여부만 반영).
|
|
updateStorageInterceptorConfig({
|
|
functionalConsented,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_ALLOWLIST,
|
|
});
|
|
updateCookieInterceptorConfig({
|
|
functionalConsented,
|
|
necessaryAllowlist: DEFAULT_NECESSARY_COOKIE_ALLOWLIST,
|
|
});
|
|
|
|
// Phase 2: 부팅 시점 functional 미동의면 allowlist 외 모든 storage/cookie 파기 (EDPB §117).
|
|
// - 재방문 시 이전 세션의 잔류 데이터 정리
|
|
// - 신규 게스트 / 거부 후 재방문 모두 동일 처리
|
|
if (!functionalConsented) {
|
|
cleanupFunctionalArtifacts();
|
|
}
|
|
|
|
if (snapshot !== null) {
|
|
setCurrentConsent({ categories: snapshot.categories, needs_renewal: snapshot.needs_renewal });
|
|
updatePreblockerConfig({
|
|
blockedDomains: customDomains,
|
|
consent: snapshot.categories,
|
|
needs_renewal: snapshot.needs_renewal,
|
|
});
|
|
if (!snapshot.needs_renewal) {
|
|
for (const [category, allowed] of Object.entries(snapshot.categories)) {
|
|
if (allowed === true && category !== 'necessary') {
|
|
restorePreblockedCategory(category);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 코어 재초기화 시 호출되는 진입점.
|
|
*
|
|
* 로케일 전환 등으로 TemplateApp 이 ActionDispatcher 를 새로 만들면
|
|
* `TemplateApp.reinitializePluginHandlers()` 가 `window.__[Plugin].initPlugin()` 을 호출한다.
|
|
* 이 이름으로 노출하지 않으면 재초기화 후 syncConsent 핸들러가 소실되어
|
|
* 동의 저장 직후 차단 엔진·인터셉터 동기화가 조용히 멈춘다.
|
|
*
|
|
* 핸들러 재등록만 수행한다 — 차단 엔진/인터셉터는 이미 설치되어 있으므로 재설치하지 않는다.
|
|
*/
|
|
function initPlugin(): void {
|
|
registerSyncHandler();
|
|
}
|
|
|
|
if (typeof window !== 'undefined') {
|
|
(window as unknown as Record<string, unknown>).__SirsoftGdpr = {
|
|
identifier: PLUGIN_IDENTIFIER,
|
|
// 코어 재초기화 시 핸들러 재등록 진입점 — 이름 고정 (TemplateApp.reinitializePluginHandlers)
|
|
initPlugin,
|
|
};
|
|
}
|
|
|
|
if (typeof document !== 'undefined') {
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
void bootstrap();
|
|
});
|
|
} else {
|
|
void bootstrap();
|
|
}
|
|
}
|
|
|
|
export { initPlugin, PLUGIN_IDENTIFIER }; |