fix(security): harden credential storage and transmission
Problem: credential and cookie files were world-readable (0644), passwords transited via `CP_CREDENTIALS` env var (visible in `/proc/PID/environ`), and Kattis/USACO echoed passwords back through stdout unnecessarily. Solution: set 0600 permissions on `cp-nvim.json` and `cookies.json` after every write, pass credentials via stdin pipe instead of env var, and stop emitting passwords in ndjson from Kattis/USACO `LoginResult` (CSES token emission unchanged).
This commit is contained in:
parent
771dbc7753
commit
0c06b4a55a
6 changed files with 10 additions and 9 deletions
|
|
@ -57,6 +57,7 @@ function M.load()
|
|||
|
||||
if vim.fn.filereadable(cache_file) == 0 then
|
||||
vim.fn.writefile({}, cache_file)
|
||||
vim.fn.setfperm(cache_file, 'rw-------')
|
||||
loaded = true
|
||||
return
|
||||
end
|
||||
|
|
@ -107,6 +108,7 @@ function M.save()
|
|||
local encoded = vim.json.encode(cache_data)
|
||||
local lines = vim.split(encoded, '\n')
|
||||
vim.fn.writefile(lines, cache_file)
|
||||
vim.fn.setfperm(cache_file, 'rw-------')
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ function M.logout(platform)
|
|||
if ok and type(data) == 'table' then
|
||||
data[platform] = nil
|
||||
vim.fn.writefile({ vim.fn.json_encode(data) }, cookie_file)
|
||||
vim.fn.setfperm(cookie_file, 'rw-------')
|
||||
end
|
||||
end
|
||||
logger.log(display .. ' credentials cleared', { level = vim.log.levels.INFO, override = true })
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ function M.login(platform, credentials, on_status, callback)
|
|||
local done = false
|
||||
run_scraper(platform, 'login', {}, {
|
||||
ndjson = true,
|
||||
env_extra = { CP_CREDENTIALS = vim.json.encode(credentials) },
|
||||
stdin = vim.json.encode(credentials),
|
||||
on_event = function(ev)
|
||||
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
||||
require('cp.cache').set_credentials(platform, ev.credentials)
|
||||
|
|
@ -392,9 +392,9 @@ function M.submit(
|
|||
local done = false
|
||||
run_scraper(platform, 'submit', { contest_id, problem_id, language, source_file }, {
|
||||
ndjson = true,
|
||||
env_extra = { CP_CREDENTIALS = vim.json.encode(credentials) },
|
||||
stdin = vim.json.encode(credentials),
|
||||
on_event = function(ev)
|
||||
if ev.credentials ~= nil then
|
||||
if ev.credentials ~= nil and next(ev.credentials) ~= nil then
|
||||
require('cp.cache').set_credentials(platform, ev.credentials)
|
||||
end
|
||||
if ev.status ~= nil then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue