-
Notifications
You must be signed in to change notification settings - Fork 0
๐ก๏ธ Sentinel: [security improvement] #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9dd0a42
ad413e5
e16f041
a439fae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,8 +301,10 @@ function preferredLanguage() { | |
| if (allowed.includes(query)) return query; | ||
|
|
||
| try { | ||
| const saved = localStorage.getItem("cwl-language"); | ||
| if (allowed.includes(saved)) return saved; | ||
| if (typeof window !== "undefined" && window.localStorage) { | ||
| const saved = window.localStorage.getItem("cwl-language"); | ||
| if (allowed.includes(saved)) return saved; | ||
| } | ||
|
Comment on lines
+304
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ Info: SSR guard does not actually protect against a missing window The new Was this helpful? React with ๐ or ๐ to provide feedback.
Comment on lines
+304
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ฉบ Stability & Availability | ๐ด Critical | โก Quick win
ํ์ฌ ์กฐ๊ฑด์ URL ํ์ฑ๊ณผ ๋ธ๋ผ์ฐ์ ์ธ์ด ์กฐํ๋ฅผ ํด๋น ์ ์ญ ๊ฐ์ฒด ๊ฒ์ฌ ๋ค๋ก ์ด๋ํ๊ณ , ์ฌ์ฉํ ๊ธฐ๋ณธ๊ฐ์ ์ ๊ณตํ์ธ์. ์์ ์์- const query = new URLSearchParams(window.location.search).get("lang");
+ const query =
+ typeof window !== "undefined"
+ ? new URLSearchParams(window.location.search).get("lang")
+ : null;
- return navigator.language?.toLowerCase().startsWith("ko") ? "ko" : "en";
+ const browserLanguage =
+ typeof navigator !== "undefined" && typeof navigator.language === "string"
+ ? navigator.language
+ : "";
+ return browserLanguage.toLowerCase().startsWith("ko") ? "ko" : "en";๐ค Prompt for AI Agents |
||
| } catch (error) { | ||
| // Fail securely: ignore localStorage errors in strict privacy modes | ||
| } | ||
|
|
@@ -385,7 +387,9 @@ function setLanguage(lang) { | |
| }); | ||
|
|
||
| try { | ||
| localStorage.setItem("cwl-language", lang); | ||
| if (typeof window !== "undefined" && window.localStorage) { | ||
| window.localStorage.setItem("cwl-language", lang); | ||
| } | ||
| } catch (error) { | ||
| // Fail securely: ignore localStorage errors | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,10 @@ def test_i18n_avoids_log_injection() -> None: | |
| content = f.read() | ||
|
|
||
| assert 'console.warn("[Security] Invalid language requested. Falling back to default.");' in content | ||
|
|
||
| def test_i18n_ssr_safe_localstorage() -> None: | ||
| """Test that localStorage access is guarded by typeof window !== 'undefined' check.""" | ||
| with open("i18n.js", "r", encoding="utf-8") as f: | ||
| content = f.read() | ||
|
|
||
| assert 'if (typeof window !== "undefined" && window.localStorage)' in content | ||
|
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ฏ Functional Correctness | ๐ Major | ๐๏ธ Heavy lift ๋ฌธ์์ด ๊ฒ์ฌ ๋์ SSR ์คํ ํ๊ท ํ ์คํธ๋ฅผ ์ถ๊ฐํ์ธ์. ํ์ฌ ๊ฒ์ฌ๋ ๋ณดํธ ์กฐ๊ฑด ๋ฌธ์์ด์ด ํ ๋ฒ ์ด์ ์กด์ฌํ๋์ง๋ง ํ์ธํฉ๋๋ค. ๋ localStorage ํธ์ถ๋ถ๋ฅผ ๋ชจ๋ ๊ฒ์ฆํ๊ณ , ๐ค Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
i18n.jsis evaluated in the stated SSR/no-window environment, the new condition is never reached: the top-leveldocument.querySelectorAllat line 400 first throwsReferenceError: document is not defined, andpreferredLanguage()also readswindow.locationat line 300 before this guard. Consequently, the string-only test passes while the advertised crash prevention remains ineffective; guard the browser-only initialization and other global accesses, or avoid claiming SSR support.Useful? React with ๐ย / ๐.