Skip to content

feat: add time parameter type and HTTP security headers#1

Merged
knep merged 3 commits into
masterfrom
feat/time-param-security-headers
May 28, 2026
Merged

feat: add time parameter type and HTTP security headers#1
knep merged 3 commits into
masterfrom
feat/time-param-security-headers

Conversation

@knep
Copy link
Copy Markdown
Owner

@knep knep commented May 28, 2026

Summary

  • New time parameter type — shows a native time picker in the UI; the script receives the time in a configurable Python strftime format (default %H:%M).
  • HTTP security headers — every response now includes X-Content-Type-Options, Referrer-Policy, and a Content-Security-Policy header alongside the existing X-Frame-Options: DENY.

Changes

time parameter type

Backend (src/model/parameter_config.py)

  • New time_format config field (default %H:%M, 24-hour clock).
  • Validation in validate_value(): parses the browser wire format (HH:MM), rejects seconds, invalid hours, non-time strings.
  • Format conversion in map_to_script(): parses %H:%M and re-formats to time_format before passing to the script.

Configuration example:

{
  "name": "start_time",
  "type": "time",
  "time_format": "%H:%M"
}

time_format is a Python strftime format string. Examples: %H:%M (default), %H%M, %I:%M %p.

Frontend

  • New web-src/src/common/components/inputs/TimeField.vue<input type="time"> with required/error handling, mirrors DateField.vue.
  • script-parameters-view.vue routes type === 'time' to TimeField.
  • Admin form (ParameterConfigForm.vue + parameter-fields.js) adds time to the type dropdown and shows a Time format field when selected.

Tests (src/tests/parameter_config_test.py) — 10 new assertions:

  • Validation: valid, midnight, 23:59, wrong format (with seconds), non-time string, out-of-range hour (25:00).
  • Map: default format passthrough, compact %H%M, with-seconds %H:%M:%S.

HTTP security headers (src/web/server.py)

Added a shared _set_security_headers() helper called by both BaseRequestHandler and BaseStaticHandler:

Header Value
X-Frame-Options DENY (was already present, now centralised)
X-Content-Type-Options nosniff
Referrer-Policy strict-origin-when-cross-origin
Content-Security-Policy default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self' ws: wss:; frame-ancestors 'none'; object-src 'none'

CSP rationale:

  • style-src 'unsafe-inline' — Materialize CSS injects inline styles.
  • connect-src ws: wss: — WebSocket used for live script output streaming.
  • frame-ancestors 'none' — equivalent to X-Frame-Options: DENY for modern browsers.
  • object-src 'none' — blocks Flash/plugin embeds.

Test plan

  • src/tests/parameter_config_test.py — 188 tests pass (10 new time tests included)
  • Full Python suite — 1638 passed, 2 pre-existing failures (htpasswd.crypt removed in Python 3.13+, unrelated)
  • Frontend — 651 tests pass, webpack build clean

🤖 Generated with Claude Code

Thomas Kpenou and others added 3 commits May 28, 2026 06:30
**`time` parameter type**
- Backend (`parameter_config.py`): `time_format` config field (default
  `%H:%M`), validation against `%H:%M`, and format conversion in
  `map_to_script()` so scripts receive the time in the configured
  strftime format.
- Frontend: new `TimeField.vue` component wrapping `<input type="time">`,
  wired into `script-parameters-view.vue`; admin form shows a
  `time_format` field when the type is `time` (via `parameter-fields.js`
  and `ParameterConfigForm.vue`).
- Tests: 10 new assertions in `parameter_config_test.py` covering
  validation (valid times, midnight, end-of-day, invalid format,
  non-time string, out-of-range hour) and format conversion (default,
  compact `%H%M`, with-seconds).

**HTTP security headers**
- Added `_set_security_headers()` helper in `server.py`, called by both
  `BaseRequestHandler` and `BaseStaticHandler`.
- New headers on every response: `X-Content-Type-Options: nosniff`,
  `Referrer-Policy: strict-origin-when-cross-origin`, and a
  `Content-Security-Policy` that allows `'self'` sources, inline styles,
  data-URI fonts/images, WebSocket connections (`ws: wss:`), and
  blocks frame embedding (`frame-ancestors 'none'`) and object embeds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The background userinfo call (which updates groups after a token
refresh) was racing against a 0.1 s access-token TTL.  On a loaded
Python 3.10 CI runner the coroutine sometimes started after the fresh
token had already expired, producing a 401 and leaving groups empty.

Fix: raise access_expiration_duration 0.1 → 0.5 s and
refresh_expiration_duration 0.6 → 2.0 s so issued tokens outlive any
realistic event-loop scheduling delay.  The hardcoded sleep in
test_success_validate_after_refresh is changed from the magic number
0.5 s to `access_expiration_duration + 0.2` so it stays valid as the
constant changes.  All other tests already reference the module-level
constants directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduce auth_info_ttl=1.0s constant so the test_read_tokens_from_request
sleep (0.6s) stays below the TTL threshold and test_success_validate_after_refresh
sleep (1.5s) stays above it, giving sufficient margin on both sides for CI jitter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@knep knep merged commit 88a7c3e into master May 28, 2026
4 checks passed
knep pushed a commit that referenced this pull request May 28, 2026
- HTTP security headers: add Permissions-Policy and HSTS to the table,
  note that WebSocket responses are now also covered
- date/time types: mention startup validation of date_format/time_format
- CI: update matrix to 3.10/3.11/3.12/3.13
- Python 3.13: add breaking-change note on DES-crypt htpasswd passwords

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant