detached 57beb4a

feat(security): add api token authentication configuration

commit
57beb4af5129fd89d92c533c43eadd71c1a7ade6
author
bamen · · 2025-09-16 08:13 UTC
parent
d923696
signature
unsigned
2 files · +16 -0
M internal/config/config.go +12 -0
@@ -35,6 +35,7 @@ type Config struct {
3535 CodecPreferences CodecConfig `mapstructure:"codec_preferences" yaml:"codec_preferences"`
3636 WebkitMemory WebkitMemoryConfig `mapstructure:"webkit_memory" yaml:"webkit_memory"`
3737 Debug DebugConfig `mapstructure:"debug" yaml:"debug"`
38+ APISecurity APISecurityConfig `mapstructure:"api_security" yaml:"api_security"`
3839 // RenderingMode controls GPU/CPU rendering selection for WebKit
3940 RenderingMode RenderingMode `mapstructure:"rendering_mode" yaml:"rendering_mode"`
4041 }
@@ -208,6 +209,14 @@ type DebugConfig struct {
208209 EnableGeneralDebug bool `mapstructure:"enable_general_debug" yaml:"enable_general_debug"`
209210 }
210211
212+// APISecurityConfig holds optional API key protection for dumb://api endpoints
213+type APISecurityConfig struct {
214+ // If non-empty, token that requests must present via `token` query param
215+ Token string `mapstructure:"token" yaml:"token"`
216+ // If true, require token for all API endpoints (except a minimal allowlist)
217+ RequireToken bool `mapstructure:"require_token" yaml:"require_token"`
218+}
219+
211220 // Manager handles configuration loading, watching, and reloading.
212221 type Manager struct {
213222 config *Config
@@ -264,6 +273,9 @@ func NewManager() (*Manager, error) {
264273 "logging.max_backups": "LOGGING_MAX_BACKUPS",
265274 "logging.max_age": "LOGGING_MAX_AGE",
266275 "logging.compress": "LOGGING_COMPRESS",
276+ // API security
277+ "api_security.token": "API_TOKEN",
278+ "api_security.require_token": "API_REQUIRE_TOKEN",
267279 }
268280
269281 for key, env := range bindings {
@@ -35,6 +35,7 @@ type Config struct {
35 CodecPreferences CodecConfig `mapstructure:"codec_preferences" yaml:"codec_preferences"`35 CodecPreferences CodecConfig `mapstructure:"codec_preferences" yaml:"codec_preferences"`
36 WebkitMemory WebkitMemoryConfig `mapstructure:"webkit_memory" yaml:"webkit_memory"`36 WebkitMemory WebkitMemoryConfig `mapstructure:"webkit_memory" yaml:"webkit_memory"`
37 Debug DebugConfig `mapstructure:"debug" yaml:"debug"`37 Debug DebugConfig `mapstructure:"debug" yaml:"debug"`
38+ APISecurity APISecurityConfig `mapstructure:"api_security" yaml:"api_security"`
38 // RenderingMode controls GPU/CPU rendering selection for WebKit39 // RenderingMode controls GPU/CPU rendering selection for WebKit
39 RenderingMode RenderingMode `mapstructure:"rendering_mode" yaml:"rendering_mode"`40 RenderingMode RenderingMode `mapstructure:"rendering_mode" yaml:"rendering_mode"`
40 }41 }
@@ -208,6 +209,14 @@ type DebugConfig struct {
208 EnableGeneralDebug bool `mapstructure:"enable_general_debug" yaml:"enable_general_debug"`209 EnableGeneralDebug bool `mapstructure:"enable_general_debug" yaml:"enable_general_debug"`
209 }210 }
210 211
212+// APISecurityConfig holds optional API key protection for dumb://api endpoints
213+type APISecurityConfig struct {
214+ // If non-empty, token that requests must present via `token` query param
215+ Token string `mapstructure:"token" yaml:"token"`
216+ // If true, require token for all API endpoints (except a minimal allowlist)
217+ RequireToken bool `mapstructure:"require_token" yaml:"require_token"`
218+}
219+
211 // Manager handles configuration loading, watching, and reloading.220 // Manager handles configuration loading, watching, and reloading.
212 type Manager struct {221 type Manager struct {
213 config *Config222 config *Config
@@ -264,6 +273,9 @@ func NewManager() (*Manager, error) {
264 "logging.max_backups": "LOGGING_MAX_BACKUPS",273 "logging.max_backups": "LOGGING_MAX_BACKUPS",
265 "logging.max_age": "LOGGING_MAX_AGE",274 "logging.max_age": "LOGGING_MAX_AGE",
266 "logging.compress": "LOGGING_COMPRESS",275 "logging.compress": "LOGGING_COMPRESS",
276+ // API security
277+ "api_security.token": "API_TOKEN",
278+ "api_security.require_token": "API_REQUIRE_TOKEN",
267 }279 }
268 280
269 for key, env := range bindings {281 for key, env := range bindings {
M internal/config/defaults.go +4 -0
@@ -140,6 +140,10 @@ func DefaultConfig() *Config {
140140 EnableScriptDebug: false,
141141 EnableGeneralDebug: false,
142142 },
143+ APISecurity: APISecurityConfig{
144+ Token: "",
145+ RequireToken: false,
146+ },
143147 RenderingMode: RenderingModeAuto,
144148 }
145149 }
@@ -140,6 +140,10 @@ func DefaultConfig() *Config {
140 EnableScriptDebug: false,140 EnableScriptDebug: false,
141 EnableGeneralDebug: false,141 EnableGeneralDebug: false,
142 },142 },
143+ APISecurity: APISecurityConfig{
144+ Token: "",
145+ RequireToken: false,
146+ },
143 RenderingMode: RenderingModeAuto,147 RenderingMode: RenderingModeAuto,
144 }148 }
145 }149 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close