Download src/security/host-launch.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/security/host-launch.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/security/host-launch.js
-
curl -L -o host-launch.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/security/host-launch.js
2.73 kB
| // ์ค๋ช ๋ฌธ์: docs/specs/host-security-guard.md (v1.0.0) | |
| // ์ค์ spawn ์ง์ ์ ์ฌ์ฉํ๋ ๊ณตํต ๊ณ์ฝ. ์๊ฒฉ ๋ชจ๋๊ฐ ๋ฏธ์ง์์ธ ๊ฒฝ๋ก๋ ํธ์คํธ ์คํ์ผ๋ก | |
| // ๋๋์๊ฐ์ง ์๋๋ค. ํ์ฌ ์คํ์ ๋ณดํธ์ ์ ์คํ์ ์ ์ฉํ ์ค์ ์ ๊ตฌ๋ถํ๋ค. | |
| const { scrubAgentEnvironment, MODEL_KEYS, RUNTIME_KEYS } = require('./agent-environment'); | |
| function policy() { | |
| const value = require('./host-security-policy').getHostSecurityPolicy(); | |
| if (!value.valid) throw Object.assign(new Error('ํธ์คํธ ๋ณด์ ์ค์ ์ ํ์ธํ ์ ์์ด ์คํ์ ์ค๋จํ์ต๋๋ค.'), { code: 'HOST_SECURITY_POLICY_INVALID' }); | |
| return value; | |
| } | |
| function assertHostPathSupported(kind) { | |
| const value = policy(); | |
| // ์๋ฒ์ listenยทOAuthยท์ธ๋ถ ๋ชจ๋ธ ์ฐ๊ฒฐ์ network deny์ ํธํ๋์ง ์๋๋ค. | |
| // ์น์ธ๋ ๋ชจ๋ธ ํต์ broker๊ฐ ์ค๋น๋๊ธฐ ์ ์๋ ์๊ฒฉ ๋ชจ๋์์ ์คํํ์ง ์๋๋ค. | |
| // PTY๋ ์์ฐ ์ข ๋ฃ ํ ๋ ๋ฆฝ ์์์ ์ข ๋ฃ ์์์ฆ์ด ์์ด ์๊ฒฉ ๋ชจ๋์์ ์์ง ์ง์ํ์ง ์๋๋ค. | |
| if (value.mode === 'strict-local' && ['gui-server', 'native-cloud-chat', 'uncontained-task', 'pty'].includes(kind)) { | |
| throw Object.assign(new Error('์ด ์คํ ๊ฒฝ๋ก๋ ์๊ฒฉ ๋ก์ปฌ ๊ฒฉ๋ฆฌ๋ฅผ ์ง์ํ์ง ์์ ์ฐจ๋จํ์ต๋๋ค.'), { code: 'HOST_ISOLATION_UNAVAILABLE' }); | |
| } | |
| return value; | |
| } | |
| async function prepareHostLaunch({ command, args = [], cwd, env = {}, kind = 'cli' }) { | |
| const selected = assertHostPathSupported(kind); | |
| let launch; | |
| try { | |
| launch = selected.mode === 'strict-local' | |
| ? await require('./host-containment').prepareContainedLaunch({ command, args, cwd, env, network: 'deny' }) | |
| : { command, args, cwd, env: scrubAgentEnvironment(env, { trustedKeys: [...MODEL_KEYS, ...RUNTIME_KEYS] }), | |
| dispose() {}, receipt: { enforced: false, mode: 'standard' } }; | |
| const assertCurrent = () => { | |
| const current = policy(); | |
| if (current.mode !== selected.mode || current.revision !== selected.revision) { | |
| throw Object.assign(new Error('์คํ ์ค๋น ์ค ๋ณด์ ์ค์ ์ด ๋ณ๊ฒฝ๋์ด ์คํ์ ์ค๋จํ์ต๋๋ค.'), { code: 'HOST_SECURITY_POLICY_CHANGED' }); | |
| } | |
| }; | |
| assertCurrent(); | |
| return { ...launch, mode: selected.mode, assertCurrent }; | |
| } catch (error) { | |
| try { await launch?.dispose(); } catch { /* ์๋ ๊ฒฉ๋ฆฌ ์คํจ๋ฅผ ๋ณด์กดํ๋ค. */ } | |
| try { require('../utils/logger').makeLogger('host-security').warn('HOST_LAUNCH_REJECTED', { code: /^[A-Z_]{1,80}$/.test(error.code || '') ? error.code : 'HOST_LAUNCH_FAILED' }); } catch { /* ์๊ฒฉ/๋ช ๋ น ์๋ฌธ์ ๊ธฐ๋กํ์ง ์๋๋ค. */ } | |
| throw error; | |
| } | |
| } | |
| module.exports = { prepareHostLaunch, assertHostPathSupported }; | |