From 5d73ac520b87a104328183803f5a632d7bf9c1e5 Mon Sep 17 00:00:00 2001 From: seo Date: Fri, 12 Jun 2026 15:43:19 +0900 Subject: [PATCH] Use server session check for access --- README.md | 2 ++ js/main.js | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 634914f..57c724b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ Home Assistant에 기록된 Galaxy 기기의 위치, 배터리, 활동 상태, 인증과 Home Assistant 호출은 `/custom/common`을 사용합니다. 브라우저 JS에는 더 이상 API Bearer 토큰이나 Home Assistant 웹훅 식별자를 직접 넣지 않습니다. +접근 확인은 JS에서 읽을 수 있는 레거시 쿠키가 아니라 `/custom/launcher/api.php?session=1` 서버 응답으로 처리합니다. 공통 인증 쿠키는 `HttpOnly`이므로 브라우저 스크립트가 직접 읽지 않습니다. + 표시할 모바일 앱 센서 목록은 `/custom/common/config.php`의 `findmydevice_sensor_sections`에서 섹션 단위로 관리합니다. 화면 CSS 원본은 `/custom/common/css/findmydevice.css`를 사용합니다. 기존 운영 HTML이 `/custom/findmydevice/css/style.css`를 참조해도 호환 파일이 공용 CSS를 import합니다. ## 운영 메모 diff --git a/js/main.js b/js/main.js index df1b7ba..c7dde0a 100644 --- a/js/main.js +++ b/js/main.js @@ -434,11 +434,16 @@ document.addEventListener('DOMContentLoaded', () => { return (window.matchMedia('(display-mode: standalone)').matches) || (window.navigator.standalone === true); } - // 조건: /findmydevice로 시작하고 access 쿠키가 없으며, PWA가 아닌 경우에만 리디렉션 - if (location.pathname.startsWith('/findmydevice') && getCookie('access') !== '9KxH6236' && !isInStandaloneMode()) { - location.replace('/blog'); - return; // 이하 코드 실행 방지 - } + if (location.pathname.startsWith('/findmydevice') && !isInStandaloneMode()) { + fetch('/custom/launcher/api.php?session=1', { credentials: 'same-origin' }) + .then(res => res.ok ? res.json() : Promise.reject()) + .then(session => { + if (!session.authenticated) { + location.replace('/blog'); + } + }) + .catch(() => location.replace('/blog')); + } const btnArea = document.querySelector('body > div.btnArea'); const pageModifyLink = btnArea?.querySelectorAll('a')[1]?.getAttribute('href') || '';