js_lis 3.1.2 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +135 -164
  2. package/main.js +32 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,164 +1,135 @@
1
- # js_lis
2
-
3
- **js_lis** is a JavaScript on-screen keyboard utility designed to reduce the risk of keystroke interception by avoiding direct hardware keyboard input in sensitive workflows.
4
-
5
- NPM package: [https://www.npmjs.com/package/js_lis](https://www.npmjs.com/package/js_lis)
6
-
7
- Web test Login + SOSK: [https://sosk-login-js-six.vercel.app](https://sosk-login-js-six.vercel.app).
8
-
9
- ---
10
-
11
- ## English
12
-
13
- ### Overview
14
-
15
- `js_lis` provides a virtual keyboard interface that can be integrated into web pages or web-based interfaces.
16
- It is intended for high-risk input scenarios where users want an additional defense layer against keylogging.
17
-
18
- ### Security Note (Keylogger and Bettercap)
19
-
20
- - `js_lis` can help reduce exposure to **traditional keyloggers** that rely on physical keystroke capture.
21
- - It is also intended to reduce risk from interception workflows commonly demonstrated with network attack tools such as **bettercap** (for example, injected key-capture scripts in compromised environments).
22
- - No client-side tool can guarantee complete protection. Security still depends on HTTPS, trusted networks, endpoint hygiene, and browser integrity.
23
-
24
- ### Key Security Features
25
-
26
- - **AES-GCM Memory Encryption**: All keystrokes are buffered and encrypted in-memory using the Web Crypto API (AES-256-GCM). The actual DOM elements never store the plaintext values.
27
- - **Shadow DOM Isolation**: The keyboard UI is rendered inside a `closed` Shadow DOM to prevent malicious external CSS/JS from sniffing or tampering with the keys.
28
- - **Anti-Clipboard Sniffing**: Blocks unauthorized `copy`, `cut`, and `execCommand("copy"/"cut")` actions to prevent clipboard hijacking.
29
- - **IME Reconciliation**: Safely handles Input Method Editors (like Thai or Chinese typing) natively without exposing the secure buffer.
30
- - **Dynamic Scrambling**: Provides an optional dynamic key scramble to thwart clickjacking or screen coordinate tracking.
31
-
32
- ### Installation
33
-
34
- ```bash
35
- npm install js_lis
36
- ```
37
-
38
- ### Basic Usage
39
-
40
- ```javascript
41
- // Example import style (adjust to your project setup)
42
- import js_lis from "js_lis";
43
-
44
- // Initialize according to your app's integration pattern
45
- // (see your local implementation files for exact wiring)
46
- ```
47
-
48
- ### How It Works + ID-based Integration
49
-
50
- `js_lis` expects specific DOM IDs:
51
-
52
- - `keyboard-container`: container where the virtual keyboard is rendered
53
- - `toggle`: optional button for show/hide keyboard
54
-
55
- When the page loads, create `VirtualKeyboard`.
56
- Then the library listens to `INPUT` and `TEXTAREA` focus/click events, tracks the active field, and injects typed characters via the virtual keys.
57
-
58
- ```html
59
- <input id="secure-input" type="password" placeholder="Enter password" />
60
- <button id="toggle" type="button">Toggle Keyboard</button>
61
- <div id="keyboard-container"></div>
62
- ```
63
-
64
- ```javascript
65
- import { VirtualKeyboard } from "./VirtualKeyboard.js";
66
-
67
- window.addEventListener("DOMContentLoaded", () => {
68
- const keyboard = new VirtualKeyboard();
69
-
70
- // Example of ID-based element access in JS
71
- const secureInput = document.getElementById("secure-input");
72
- if (secureInput) secureInput.focus();
73
- });
74
- ```
75
-
76
- ### Recommended Deployment Practices
77
-
78
- - Serve over HTTPS only.
79
- - Use a strict Content Security Policy (CSP).
80
- - Avoid running on untrusted or MITM-prone networks.
81
- - Keep browser and OS security patches up to date.
82
- - Pair with endpoint protection and monitoring.
83
-
84
- ---
85
-
86
- ## ภาษาไทย (ทางการ)
87
-
88
- ### ภาพรวม
89
-
90
- `js_lis` เป็นเครื่องมือคีย์บอร์ดเสมือน (Virtual Keyboard) สำหรับ JavaScript ที่ออกแบบมาเพื่อลดความเสี่ยงจากการดักจับการพิมพ์ โดยหลีกเลี่ยงการป้อนข้อมูลผ่านคีย์บอร์ดฮาร์ดแวร์โดยตรงในขั้นตอนที่มีความอ่อนไหวด้านความปลอดภัย
91
-
92
- อ้างอิงแพ็กเกจบน npm: [https://www.npmjs.com/package/js_lis](https://www.npmjs.com/package/js_lis)
93
-
94
- ตัวอย่างหน้า Login + SOSK: [https://sosk-login-js-six.vercel.app](https://sosk-login-js-six.vercel.app).
95
-
96
- ### หมายเหตุด้านความปลอดภัย (Keylogger และ Bettercap)
97
-
98
- - `js_lis` สามารถช่วยลดความเสี่ยงจาก **keylogger แบบดั้งเดิม** ที่มุ่งดักข้อมูลจากการกดแป้นพิมพ์จริง
99
- - รวมถึงสามารถช่วยลดความเสี่ยงจากรูปแบบการโจมตีที่มักสาธิตผ่านเครื่องมือเครือข่ายอย่าง **bettercap** (เช่น การแทรกสคริปต์เพื่อดักรับข้อมูลการป้อนในสภาพแวดล้อมที่ถูกบุกรุก)
100
- - อย่างไรก็ตาม เครื่องมือฝั่งผู้ใช้เพียงอย่างเดียวไม่สามารถรับประกันการป้องกันได้สมบูรณ์ จำเป็นต้องใช้ร่วมกับ HTTPS, เครือข่ายที่เชื่อถือได้, ความปลอดภัยของเครื่องผู้ใช้ และความน่าเชื่อถือของเบราว์เซอร์
101
-
102
- ### ฟีเจอร์ด้านความปลอดภัยที่สำคัญ
103
-
104
- - **การเข้ารหัสหน่วยความจำด้วย AES-GCM**: ทุกการกดแป้นพิมพ์จะถูกบัฟเฟอร์และเข้ารหัสในหน่วยความจำชั่วคราวด้วย Web Crypto API (AES-256-GCM) ข้อความต้นฉบับจะไม่ถูกเก็บเป็น plaintext ใน DOM elements
105
- - **การแยกส่วนด้วย Shadow DOM**: หน้าคีย์บอร์ดจะถูกเรนเดอร์อยู่ภายใน `closed` Shadow DOM เพื่อป้องกันไม่ให้ CSS/JS จากภายนอกแอบอ่านหรือแก้ไขปุ่มคีย์บอร์ด
106
- - **ป้องกันการแอบอ่านคลิปบอร์ด (Anti-Clipboard Sniffing)**: บล็อกการดักจับคำสั่ง `copy`, `cut`, และ `execCommand` ที่ไม่ได้รับอนุญาตเพื่อป้องกันการขโมยข้อมูลจากคลิปบอร์ด
107
- - **รองรับ IME อย่างปลอดภัย**: จัดการกับการพิมพ์ผ่าน Input Method Editors (เช่น ภาษาไทย) ได้อย่างถูกต้องโดยที่ยังคงแยกบักเฟอร์ข้อมูลอย่างปลอดภัย
108
- - **การสลับตำแหน่งปุ่ม (Dynamic Scrambling)**: มีฟังก์ชันสลับตำแหน่งปุ่มแบบสุ่มเพื่อป้องกันการติดตามพิกัดการคลิกบนหน้าจอหรือ clickjacking
109
-
110
- ### การติดตั้ง
111
-
112
- ```bash
113
- npm install js_lis
114
- ```
115
-
116
- ### การใช้งานเบื้องต้น
117
-
118
- ```javascript
119
- // ตัวอย่างการนำเข้า (ปรับตามโครงสร้างโปรเจกต์ของท่าน)
120
- import js_lis from "js_lis";
121
-
122
- // เรียกใช้งานตามรูปแบบการเชื่อมต่อของแอปพลิเคชัน
123
- ```
124
-
125
- ### หลักการทำงาน + การเรียกใช้ผ่าน ID ใน JavaScript
126
-
127
- `js_lis` ต้องอาศัย DOM `id` หลักดังนี้
128
-
129
- - `keyboard-container`: พื้นที่สำหรับ render คีย์บอร์ดเสมือน
130
- - `toggle`: ปุ่มสำหรับสลับแสดง/ซ่อนคีย์บอร์ด (ถ้ามี)
131
-
132
- เมื่อหน้าเว็บโหลดเสร็จ ให้สร้าง `VirtualKeyboard` จากนั้นระบบจะดักเหตุการณ์ focus/click ของ `INPUT` และ `TEXTAREA` เพื่อระบุช่องที่กำลังใช้งาน และป้อนค่าผ่านปุ่มบนคีย์บอร์ดเสมือน
133
-
134
- ```html
135
- <input id="secure-input" type="password" placeholder="กรอกรหัสผ่าน" />
136
- <button id="toggle" type="button">แสดง/ซ่อนคีย์บอร์ด</button>
137
- <div id="keyboard-container"></div>
138
- ```
139
-
140
- ```javascript
141
- import { VirtualKeyboard } from "./VirtualKeyboard.js";
142
-
143
- window.addEventListener("DOMContentLoaded", () => {
144
- const keyboard = new VirtualKeyboard();
145
-
146
- // ตัวอย่างการเรียกใช้งาน element ผ่าน id
147
- const secureInput = document.getElementById("secure-input");
148
- if (secureInput) secureInput.focus();
149
- });
150
- ```
151
-
152
- ### แนวทางการใช้งานที่แนะนำ
153
-
154
- - ให้บริการผ่าน HTTPS เท่านั้น
155
- - กำหนดนโยบาย Content Security Policy (CSP) อย่างเข้มงวด
156
- - หลีกเลี่ยงการใช้งานบนเครือข่ายที่ไม่เชื่อถือได้หรือมีความเสี่ยง MITM
157
- - อัปเดตแพตช์ความปลอดภัยของระบบปฏิบัติการและเบราว์เซอร์อย่างสม่ำเสมอ
158
- - ใช้งานร่วมกับระบบป้องกันและเฝ้าระวังความปลอดภัยของอุปกรณ์ปลายทาง
159
-
160
- ---
161
-
162
- ## License
163
-
164
- ISC
1
+ # js_lis (SOSK - Secure On-Screen Keyboard)
2
+
3
+ **js_lis** is a high-security JavaScript on-screen keyboard (SOSK) designed to mitigate the risk of keystroke interception. Unlike traditional virtual keyboards, it employs multi-layered security protocols to protect sensitive data from keyloggers, clipboard sniffers, and man-in-the-browser (MITB) attacks.
4
+
5
+ NPM package: [https://www.npmjs.com/package/js_lis](https://www.npmjs.com/package/js_lis)
6
+ Web Test Login + SOSK: [https://sosk-login-js-six.vercel.app](https://sosk-login-js-six.vercel.app)
7
+
8
+ ---
9
+
10
+ ## English
11
+
12
+ ### Overview
13
+
14
+ `js_lis` provides a secure input interface that isolates user interactions from the host page. It is engineered for scenarios where standard hardware input is too risky, such as financial transactions, credential entry, or private communication.
15
+
16
+ ### Advanced Security Architecture
17
+
18
+ 1. **AES-GCM Memory Encryption**:
19
+ * **SecureBufferStore**: Uses a `WeakMap` to store encrypted buffers associated with input elements. This ensures that even if an attacker leaks the object, the data remains protected.
20
+ * **Cryptographic Strength**: Employs **AES-256-GCM** via the Web Crypto API. Each buffer is encrypted with a unique IV (Initialization Vector) generated per write operation.
21
+ * **Automatic Fallback**: Gracefully degrades to a non-encrypted buffer in insecure (HTTP) environments where the Web Crypto API is unavailable.
22
+
23
+ 2. **Shadow DOM Isolation**:
24
+ * The keyboard UI is rendered within a **`closed` Shadow DOM**.
25
+ * **Isolation**: This prevents the host page's CSS from altering the keyboard appearance (anti-clickjacking) and blocks third-party JavaScript from inspecting the keyboard's internal DOM structure.
26
+
27
+ 3. **IME Reconciliation Engine**:
28
+ * Natively handles Input Method Editors (IME) for languages like Thai, Chinese, or Japanese.
29
+ * **Sync Logic**: intercepts `compositionstart`, `compositionupdate`, and `compositionend` events to synchronize complex multi-character inputs with the encrypted secure buffer without exposing intermediate states.
30
+
31
+ 4. **Anti-Clipboard Sniffing & Secure Paste**:
32
+ * **Event Blocking**: Intercepts and blocks unauthorized `copy` and `cut` events when the virtual keyboard is active.
33
+ * **Command Sanitization**: Monkey-patches `document.execCommand` to disable clipboard operations programmatically.
34
+ * **Secure Paste**: Implements an explicit `securePaste()` method using the `navigator.clipboard` API to ensure data only enters the secure buffer when intended.
35
+
36
+ 5. **Physical Keyboard Synchronization**:
37
+ * Captures hardware `keydown` and `input` events to keep the secure buffer updated in real-time, even when a user switches between virtual and physical input.
38
+
39
+ ### Installation
40
+
41
+ ```bash
42
+ npm install js_lis
43
+ ```
44
+
45
+ ### Technical Integration
46
+
47
+ The recommended implementation uses a singleton pattern to manage the keyboard instance across your application.
48
+
49
+ #### DOM Requirements
50
+ - `keyboard-container`: The target div where the keyboard will be injected.
51
+ - `toggle` (Optional): A button to show/hide the keyboard.
52
+
53
+ ```html
54
+ <input id="login-input" type="password" placeholder="Enter Password" />
55
+ <div id="keyboard-container"></div>
56
+ <button id="toggle">Toggle Keyboard</button>
57
+ ```
58
+
59
+ #### Initialization
60
+ ```javascript
61
+ import { getKeyboard } from "js_lis/main.js";
62
+
63
+ // Get the existing singleton instance
64
+ const keyboard = getKeyboard();
65
+
66
+ // The keyboard automatically monitors all INPUT and TEXTAREA elements.
67
+ // To manually focus an element and start secure buffer tracking:
68
+ const input = document.getElementById("login-input");
69
+ keyboard.setCurrentInput(input);
70
+ ```
71
+
72
+ ### Supported Layouts
73
+ - **Full**: QWERTY + Numpad + Symbols.
74
+ - **English/Thai**: Standard localized layouts.
75
+ - **Numpad**: Numeric entry only.
76
+ - **Symbols**: Special characters.
77
+ - **Dynamic Scramble**: Optional randomization of key positions to thwart coordinate tracking.
78
+
79
+ ---
80
+
81
+ ## ภาษาไทย (Technical Overview)
82
+
83
+ ### ภาพรวม
84
+ `js_lis` คือระบบคีย์บอร์ดเสมือนที่มีความปลอดภัยสูง (Secure On-Screen Keyboard - SOSK) ออกแบบมาเพื่อป้องกันการดักจับข้อมูลการพิมพ์ (Keystroke Interception) โดยใช้เทคโนโลยีการป้องกันหลายชั้นเพื่อความปลอดภัยสูงสุดในระดับ Memory และ DOM Level
85
+
86
+ ### สถาปัตยกรรมด้านความปลอดภัยขั้นสูง
87
+
88
+ 1. **การเข้ารหัสหน่วยความจำระดับ AES-GCM**:
89
+ * **SecureBufferStore**: ใช้ `WeakMap` ในการเก็บข้อมูลจำลอง (Buffer) ที่ถูกเข้ารหัสแยกตาม Input Element เพื่อป้องกันการรั่วไหลของข้อมูลหาก Object ถูกเข้าถึงโดยไม่ได้รับอนุญาต
90
+ * **มาตรฐานการเข้ารหัส**: ใช้ **AES-256-GCM** ผ่าน Web Crypto API โดยทุกการอัปเดตข้อมูลจะมีการสร้าง IV (Initialization Vector) ใหม่เสมอ
91
+ * **ระบบสำรอง (Fallback)**: หากใช้งานผ่านโปรโตคอล HTTP (ซึ่งไม่มี SubtleCrypto) ระบบจะเปลี่ยนมาใช้การเก็บข้อมูลแบบ Plaintext โดยอัตโนมัติ
92
+
93
+ 2. **การแยกส่วนด้วย Shadow DOM (Closed Mode)**:
94
+ * หน้าจอคีย์บอร์ดจะถูกสร้างขึ้นภายใน **Closed Shadow DOM**
95
+ * **การแยกส่วน (Isolation)**: ป้องกันไม่ให้ CSS จากภายนอกเข้ามาแก้ไขหน้าตาคีย์บอร์ด (ป้องกัน Clickjacking) และป้องกันไม่ให้ JavaScript จากภายนอกสามารถอ่านโครงสร้างปุ่มภายในได้
96
+
97
+ 3. **ระบบประสานงาน IME (IME Reconciliation Engine)**:
98
+ * รองรับการพิมพ์ภาษาไทยและภาษาอื่นๆ ที่ต้องใช้การประสมคำ (Composition) ได้อย่างสมบูรณ์
99
+ * **การซิงโครไนซ์**: ดักจับ Event `compositionstart/update/end` เพื่อนำข้อมูลมาประมวลผลร่วมกับ Secure Buffer โดยที่ข้อมูลล่าสุดจะถูกเข้ารหัสทันทีที่จบการประสมคำ
100
+
101
+ 4. **การป้องกันคลิปบอร์ดและการวางข้อมูลอย่างปลอดภัย (Anti-Clipboard)**:
102
+ * **การบล็อกเหตุการณ์**: บล็อกคำสั่ง `copy` และ `cut` เมื่อมีการใช้งานคีย์บอร์ดเสมือน
103
+ * **การป้องกันโปรแกรมมิ่ง**: ทำการ Override `document.execCommand` เพื่อปิดการทำงานที่เกี่ยวกับคลิปบอร์ดผ่านสคริปต์
104
+ * **Secure Paste**: รองรับการวางข้อมูลผ่าน `navigator.clipboard` API โดยเฉพาะเพื่อให้มั่นใจว่าข้อมูลจะถูกส่งเข้าสู่ Secure Buffer โดยตรง
105
+
106
+ 5. **การซิงโครไนซ์กับคีย์บอร์ดจริง**:
107
+ * ติดตามเหตุการณ์ `keydown` และ `input` จากคีย์บอร์ดฮาร์ดแวร์เพื่ออัปเดตข้อมูลใน Secure Buffer ให้ตรงกันเสมอ ไม่ว่าจะพิมพ์ผ่านช่องทางใด
108
+
109
+ ### การเรียกใช้งานทางเทคนิค
110
+
111
+ แนะนำให้ใช้งานในรูปแบบ Singleton เพื่อประสิทธิภาพสูงสุด
112
+
113
+ ```javascript
114
+ import { getKeyboard } from "js_lis/main.js";
115
+
116
+ // เข้าถึง Instance ที่ถูกสร้างไว้แล้ว
117
+ const osk = getKeyboard();
118
+
119
+ // ระบบจะคอยตรวจสอบ INPUT และ TEXTAREA บนหน้าเว็บโดยอัตโนมัติ
120
+ // หากต้องการกำหนดช่องรับข้อมูลที่ต้องการเริ่มต้นใช้งาน:
121
+ const myInput = document.getElementById("password-field");
122
+ osk.setCurrentInput(myInput);
123
+ ```
124
+
125
+ ### เลย์เอาต์ที่รองรับ
126
+ - **Full**: คีย์บอร์ดเต็มรูปแบบ (QWERTY + ตัวเลข + สัญลักษ์)
127
+ - **English / Thai**: คีย์บอร์ดภาษาอังกฤษและภาษาไทยมาตราฐาน
128
+ - **Numpad / Symbols**: เฉพาะตัวเลขหรือสัญลักษณ์พิเศษ
129
+ - **Dynamic Scramble**: ฟังก์ชันสลับตำแหน่งปุ่มแบบสุ่มเพื่อป้องกันการติดตามพิกัดการคลิก
130
+
131
+ ---
132
+
133
+ ## License
134
+
135
+ ISC
package/main.js CHANGED
@@ -1,4 +1,32 @@
1
- import { VirtualKeyboard } from "./VirtualKeyboard.js";
2
-
3
- // สร้างออบเจกต์คีย์บอร์ดแล้ว export ทันที (ไม่เอาไปแปะไว้ใน window.keyboard แล้ว)
4
- export const keyboard = new VirtualKeyboard();
1
+ import { VirtualKeyboard } from "./VirtualKeyboard.js";
2
+
3
+ let keyboardInstance = null;
4
+
5
+ // init + singleton
6
+ function initKeyboard() {
7
+ if (keyboardInstance) return keyboardInstance;
8
+
9
+ const container = document.getElementById("keyboard-container");
10
+ if (!container) {
11
+ console.warn("Keyboard container not found");
12
+ return null;
13
+ }
14
+
15
+ keyboardInstance = new VirtualKeyboard();
16
+ return keyboardInstance;
17
+ }
18
+
19
+ // getter (ไว้ใช้จากที่อื่น ถ้าจำเป็น)
20
+ export function getKeyboard() {
21
+ return keyboardInstance;
22
+ }
23
+
24
+ // init ตอน DOM พร้อม
25
+ window.addEventListener("DOMContentLoaded", () => {
26
+ try {
27
+ initKeyboard();
28
+ console.log("Keyboard initialized safely");
29
+ } catch (err) {
30
+ console.error("Keyboard init error:", err);
31
+ }
32
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_lis",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"