security: HR handlers missing authentication guards #45
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_biz#45
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
All six HR handlers in
crates/hero_biz_ui/src/web/handlers/mod.rsare missing session authentication guards. Any unauthenticated request can read and write employee data.Affected handlers
hr_listGET /c/:context/hrhr_detailGET /c/:context/hr/:idhr_newGET /c/:context/hr/newhr_createPOST /c/:context/hr/newhr_editGET /c/:context/hr/:id/edithr_updatePOST /c/:context/hr/:id/editRoot cause
Each handler calls
get_sessionbut only to populateuser_namein the template. When the session isNone,user_namedefaults to an empty string and the handler continues:Fix
Add auth guard at the top of each handler before any store calls.
GET handlers (
hr_list,hr_detail,hr_new,hr_edit):POST handlers (
hr_create,hr_update):Same pattern already used correctly in
task_update_statusandperson_link_delete.Context
Identified during review of PR #21 (
development_casper->development).Implementation Spec for Issue #45
Objective
Add session authentication guards to all six HR handlers in
crates/hero_biz_ui/src/web/handlers/mod.rs. Currently any unauthenticated request can read and write employee data because each handler callsget_sessiononly to populateuser_name, allowing execution to continue when the session isNone.Root Cause Analysis
The
get_sessionfunction has a demo-mode fallback via.or_else(...)that returns a syntheticSessionwhen no real cookie exists. This meansget_sessioncurrently never returnsNonein practice, so the vulnerability is dormant. However, the fix must be applied now so that removing the demo fallback in future enforces authentication with no further handler changes needed.Two guard patterns are already in use:
Pattern B — GET handlers (redirect):
Pattern A — POST handlers (401):
Files to Modify
crates/hero_biz_ui/src/web/handlers/mod.rs— the only file needing changesImplementation Plan
Step 1:
hr_list(GET, ~line 8378)Replace:
With Pattern B. Add
.into_response()to the terminalHtml(template.render()).Step 2:
hr_detail(GET, ~line 8404)Same Pattern B substitution. Terminal
Html(...)already has.into_response().Step 3:
hr_new(GET, ~line 8463)Pattern B. Add
.into_response()to terminalHtml(template.render()).Step 4:
hr_create(POST, ~line 8487)Replace:
With Pattern A.
Step 5:
hr_edit(GET, ~line 8571)Pattern B. Add
.into_response()if missing from terminal expression.Step 6:
hr_update(POST, ~line 8600)Pattern A (same as hr_create).
Step 7: Build verification
Zero compiler errors required.
Acceptance Criteria
cargo build -p hero_biz_uipasses cleanNotes
auth_middleware(lines 47–69) should NOT be uncommented as part of this fix — the per-handler approach is the established pattern.into_response()must be added to terminalHtml(...)expressions in GET handlers because the function now has multipleIntoResponsebranches with different concrete types.Build Results
Status: PASS
cargo build -p hero_biz_ui completed with 0 errors.
Implementation Complete
All six HR handlers in
crates/hero_biz_ui/src/web/handlers/mod.rsnow have session authentication guards.Changes
GET handlers (
hr_list,hr_detail,hr_new,hr_edit) — redirect to login on missing session:POST handlers (
hr_create,hr_update) — return 401 on missing session:Terminal
Html(template.render())expressions inhr_listandhr_newupdated to.into_response()to satisfy axum's multi-branch type unification.Build
cargo build -p hero_biz_ui— 0 errors.Acceptance Criteria
cargo build -p hero_biz_uipasses clean