High School AdvancedA11.6Secure Software Architecture

Lesson A11.6

Secure Error Handling and Logging

Software will fail sometimes. Secure architecture does not pretend every error can be prevented. Instead, it designs how failures are contained, communicated, recorded, investigated, and learned from.

This lesson teaches you to separate user-facing errors from operational diagnostics, security audit events, and protected debugging evidence while keeping secrets and unnecessary private data out of logs.

Lesson Progress

Secure Error Handling and Logging

High School AdvancedA11: Secure Software Architecture • Lesson 6 of 10

60% complete

Readiness Check

A11.6 Entry Readiness

0/4 ready

Professional Hook

One Failure, Four Different Audiences

Imagine the fictional Northbridge portal fails while saving a privileged account change. The end user needs to know that the action did not complete. The operator needs to know which service failed. The security team needs an auditable record of the attempted privileged action. A developer may need deeper diagnostic context.

Those audiences should not all receive the same message.

End user

Explain what the user needs to know and what safe action they can take next.

Include: Simple outcome, retry guidance, support reference, neutral error code when useful.

Avoid: Internal paths, stack traces, secrets, database details, dependency names, raw exception objects.

Application operator

Understand service health, failed workflows, degraded dependencies, and operational recovery needs.

Include: Service, environment, operation, correlation ID, result, dependency status, retry state.

Avoid: Secret values, unnecessary payloads, private records, raw credentials.

Security defender

Investigate important identity, authorization, privilege, configuration, and security-control events.

Include: Actor or service identity, target reference, action, result, timestamp, source, correlation ID, policy decision.

Avoid: Passwords, tokens, keys, cookies, recovery codes, full sensitive request bodies.

Protected diagnostic reviewer

Analyze deeper implementation failures in a tightly controlled diagnostic context.

Include: Sanitized exception class, component, operation, stack location or trace reference when approved, correlation ID.

Avoid: Anything broader than needed for troubleshooting; secret or private values should remain redacted.

Learning Objectives

Five Capabilities for This Lesson

1

Explain how secure error handling protects users while still giving defenders and engineers enough evidence to understand what happened.

2

Separate user-facing messages, operational diagnostics, security telemetry, and protected debugging evidence by audience and purpose.

3

Design logging requirements that capture useful context without exposing secrets, unnecessary private data, or sensitive implementation details.

4

Evaluate fictional logging evidence for coverage, redaction, source health, retention, access, correlation, and auditability.

5

Build an error-handling and logging design that becomes the sixth artifact in the A11 Secure Software Design Assessment.

Why It Matters

Errors Can Leak, Hide, or Preserve Evidence

Poor error handling can expose implementation details, private data, or secrets. Poor logging can hide important security decisions or create huge amounts of noisy data. Good design balances privacy, usability, operations, investigation, and accountability.

Protect the user

Give understandable guidance without exposing protected technical details.

Protect the evidence

Record important decisions and outcomes with enough context to investigate later.

Protect the data

Minimize what gets logged and keep secret or private values out of telemetry.

Core Framework

Eight Steps for Secure Failure Handling

01

Detect the failure

What condition occurred and which component recognized it?

Distinguish validation failures, authorization denials, dependency failures, internal faults, rate or capacity conditions, and expected business-rule outcomes.

Evidence: Application event, safe exception metadata, dependency state, request correlation.
02

Contain the impact

What should the system do to prevent the failure from spreading?

Stop unsafe processing, preserve data integrity, use safe defaults, avoid partial privileged changes, and protect important state.

Evidence: Transaction result, rollback state, workflow status, resilience design.
03

Respond safely

What should the user or calling service be told?

Return a useful but bounded response that does not expose internal implementation detail or sensitive information.

Evidence: User-facing response template, API error contract, support reference.
04

Record useful evidence

What context do operators and defenders need?

Record service, environment, operation, actor or workload reference where appropriate, result, timestamp, correlation identifier, and policy decision.

Evidence: Operational event, security audit event, log schema.
05

Redact and minimize

Which values must never appear in logs or errors?

Remove secrets, credentials, session tokens, private keys, recovery codes, unnecessary private data, and overly detailed request content.

Evidence: Logging requirement, redaction rule, sample sanitized event, validation result.
06

Route and retain

Where should the evidence go and how long should it remain?

Send different event classes to appropriate protected destinations with defined access, retention, ownership, and review expectations.

Evidence: Logging architecture, retention policy, access-control summary, source ownership.
07

Monitor source health

How does the team know the logging path itself still works?

Track freshness, parsing, expected volume, missing sources, delayed delivery, schema drift, and retention health.

Evidence: Source-health dashboard, heartbeat events, parser status, ingestion metrics.
08

Learn and improve

What recurring failures should change the design?

Use trends, incidents, support patterns, and control failures to refine requirements, resilience, validation, and architecture.

Evidence: Post-incident review, trend report, requirement update, change trigger.

Vocabulary

Error Handling and Logging Terms

Error handling

The design and process used to detect, contain, communicate, record, and recover from failures.

User-facing error

A bounded message shown to a user or calling client that explains the outcome without revealing unnecessary internal detail.

Operational log

Telemetry used to understand service health, workflows, dependencies, performance, and recovery.

Security audit event

A record of a security-relevant action or decision such as authorization, privileged change, account recovery, or configuration modification.

Correlation ID

A non-secret identifier used to connect related events across services or stages of one workflow.

Redaction

Removing or masking sensitive values that should not appear in logs, errors, dashboards, or reports.

Data minimization

Recording only the information needed for the stated operational or security purpose.

Source health

Evidence that a logging source is current, delivering expected events, parsing correctly, and meeting retention expectations.

Schema

The defined fields, types, and structure expected in an event.

Retention

The approved period for keeping logs or diagnostic evidence.

Diagnostic channel

A more restricted evidence path used for deeper troubleshooting than ordinary user or operational output.

Fail safe

A design behavior that prefers a safer state when an important control or dependency cannot make a trustworthy decision.

Logging Domains

Eight Event Areas Worth Designing Explicitly

AUTHN

Authentication events

Examples

Successful staff sign-in, denied sign-in, disabled identity, session establishment failure.

Important context

Identity reference, result, source, timestamp, correlation ID, reason category.

Avoid

Passwords, tokens, recovery codes, full identity claims.

AUTHZ

Authorization decisions

Examples

Allowed or denied access to assigned student record, privileged action approval.

Important context

Actor reference, target reference, action, decision, policy or role basis, correlation ID.

Avoid

Full private record content or unnecessary user attributes.

PRIV

Privileged actions

Examples

Role change, account recovery, configuration change, broad data export approval.

Important context

Actor, target reference, action, result, approval reference, timestamp, correlation ID.

Avoid

Secret values, full export data, private notes unrelated to the action.

DATA

Sensitive data operations

Examples

Record creation, deletion request, approved export, retention action.

Important context

Actor or service, data category, operation, result, policy reference, target identifier.

Avoid

Full record content when metadata is sufficient.

CFG

Configuration changes

Examples

Authorization baseline change, logging schema update, feature-flag change.

Important context

Actor, changed setting reference, environment, old/new state classification, approval reference.

Avoid

Secret configuration values.

DEP

Dependency and integration health

Examples

Scheduling vendor unavailable, notification retry, dependency timeout, supplier API degradation.

Important context

Dependency ID, operation, result, duration, retry state, environment, correlation ID.

Avoid

Vendor credentials, private payloads, unnecessary response bodies.

ERR

Application failures

Examples

Unexpected server exception, workflow rollback, failed persistence operation.

Important context

Sanitized exception category, service, operation, environment, correlation ID, impact class.

Avoid

Raw stack traces in user-facing output, secrets, full database statements, private data.

SRC

Logging source health

Examples

Missing heartbeat, delayed ingestion, parser failure, unexpected event-volume drop.

Important context

Source ID, last-seen time, ingestion status, parser status, expected/actual volume.

Avoid

Assuming no alerts means the source is healthy.

User vs. Defender

One Event Can Produce Different Outputs

Strong error handling creates different outputs from the same underlying event depending on the audience.

Authorization denied

User

You do not have permission to perform this action. Reference: NB-403.

Operator

Action denied by authorization policy; correlation ID links to audit event.

Security

Actor ref, target ref, action, decision=deny, policy ref, correlation ID.

Dependency unavailable

User

This feature is temporarily unavailable. Your main record was not changed. Please try again later.

Operator

Scheduling dependency unavailable; retry queue active; correlation ID recorded.

Security

Only if the failure is security-relevant; otherwise operational evidence may be sufficient.

Unexpected internal error

User

We could not complete the request. Reference: NB-500-7F2.

Operator

Service and operation failed; sanitized exception category and correlation ID available.

Security

Escalate if the event pattern or affected workflow meets a defined security-monitoring rule.

Validation error

User

One or more fields need attention. Review the highlighted entries.

Operator

Usually low-level operational evidence only unless repeated patterns matter to service health.

Security

Do not log full private field values merely because validation failed.

Fake Dashboard

Northbridge Logging Assurance Dashboard

Fictional telemetry-health data

Critical audit sources

12

11 healthy, 1 degraded

Redaction compliance

98.7%

One diagnostic schema requires remediation

Events with correlation IDs

96%

Legacy reporting workflow remains incomplete

Source freshness

99.4%

Authorization source delayed for 7 minutes earlier today

Fake SOC Alert

Authorization Audit Source Freshness Degraded

Source: Fictional Source Health Monitor • Time: 09:19

Medium Severity
The authorization audit source has not delivered new events for seven minutes. Parser state is healthy, but expected event volume is above zero.
Defensive recommendation: Treat event absence as an evidence-quality issue until source freshness recovers. Do not assume no authorization activity occurred.

Event Register

Six Fictional Logging Requirements

LOG-01Security auditConfirmed

Counselor record access decision

Fields

Actor ref, student ref, action, decision, assignment-policy ref, timestamp, correlation ID

Redaction

No counseling-note content, passwords, tokens, or unnecessary profile data

Retention

Security audit retention class

Owner

Application + Security Monitoring

LOG-02Security auditConfirmed

Privileged account recovery

Fields

Approver ref, operator ref, target account ref, action, result, approval ref, timestamp, correlation ID

Redaction

No recovery codes, secrets, session values, or private identity-proof content

Retention

Privileged audit retention class

Owner

Identity Platform + Security Monitoring

LOG-03OperationalConfirmed

Scheduling vendor unavailable

Fields

Dependency ID, operation, result, retry state, duration, environment, correlation ID

Redaction

No vendor token, student appointment payload, or private fields

Retention

Operational retention class

Owner

Integration Owner

LOG-04Protected diagnosticConditional

Unhandled application exception

Fields

Service, operation, sanitized exception class, environment, correlation ID, trace reference

Redaction

No stack trace to user, no database credentials, no request body, no private record content

Retention

Restricted diagnostic retention class

Owner

Application Engineering

LOG-05Source healthConfirmed

Authorization source heartbeat

Fields

Source ID, last-seen time, parser state, expected volume, actual volume

Redaction

No user records

Retention

Monitoring health retention class

Owner

Security Monitoring

LOG-06OperationalUnknown

Legacy report failure

Fields

Report job ref, component ref, result, duration, environment, correlation ID

Redaction

No generated report content

Retention

Operational retention class

Owner

Reporting Team

Fake Log Panel

Fictional Error and Logging Evidence

training-log-viewer.log
[09:02] AUTHZ decision=DENY actor=usr-102 target=stu-884 policy=ASSIGNMENT correlation=NB-91A
[09:08] PRIV action=ACCOUNT_RECOVERY result=APPROVED approval=APR-224 correlation=NB-92C
[09:14] DEP dependency=SCHEDULING result=UNAVAILABLE retry=QUEUED correlation=NB-93F
[09:19] SRC source=AUTHZ_AUDIT last_seen=09:12 parser=HEALTHY freshness=DEGRADED
[09:27] ERR service=RECORD_API class=StorageOperationError correlation=NB-94B redaction=PASS
[09:41] LOG legacy_report correlation_id=MISSING status=UNKNOWN
[09:55] SRC source=AUTHZ_AUDIT freshness=RECOVERED backlog=0

Training note: this is fake data for defensive analysis practice only.

Review Questions

Eighteen Questions for Error and Logging Design

1

Who is the audience for this error or event?

2

What decision should this evidence support?

3

Which fields are required?

4

Which sensitive values are forbidden?

5

Does the user-facing message expose internal implementation detail?

6

Does the event identify service and environment?

7

Is actor or workload identity needed?

8

Is target reference needed?

9

Is a correlation ID present?

10

Is the result or policy decision explicit?

11

Is the event schema stable and documented?

12

Who owns the source?

13

Who can access the evidence?

14

How long should it be retained?

15

How is source health measured?

16

What happens if the logging destination is unavailable?

17

Which events should become alerts?

18

What change triggers require schema or privacy re-review?

Analyze the Evidence

Evidence Analysis: Missing Correlation ID

The legacy reporting workflow records job reference, component reference, result, duration, and environment.
The event does not contain a correlation ID.
The workflow spans the application, reporting service, and storage service.
No alternative cross-service linkage is documented.

What is the strongest conclusion about LOG-06?

Source Health

No Logs Is Not the Same as No Activity

Security teams depend on logging pipelines. If a source stops sending events, dashboards may look quiet even while the software is active. That is why source-health evidence belongs in the architecture.

Freshness

When was the last expected event or heartbeat received?

Volume

Is current event volume within an expected range?

Parsing

Are events being interpreted by the expected schema?

Ingestion

Are events arriving at the intended destination?

Retention

Are required events still available for the approved period?

Ownership

Who responds when the source becomes stale or degraded?

Common Mistakes

Eight Ways Error and Logging Design Fails

1

Showing stack traces to users

Why it fails: Internal component names, paths, line references, dependency details, and implementation context can leak unnecessarily.

Better approach: Give users a bounded message and correlation reference; keep deeper diagnostics in restricted channels.

2

Logging everything

Why it fails: Excess data increases privacy, access, retention, storage, and investigation burden.

Better approach: Record the minimum fields needed for the operational or security purpose.

3

Logging secrets

Why it fails: Logs often have broader access and longer retention than secret stores.

Better approach: Use secret metadata or record IDs, never secret values.

4

No correlation ID

Why it fails: Multi-service workflows become difficult to reconstruct without a safe way to connect related events.

Better approach: Use a non-secret correlation identifier across the workflow.

5

No source-health monitoring

Why it fails: A silent logging pipeline can make defenders believe nothing happened when evidence is simply missing.

Better approach: Track source freshness, expected volume, parser state, and ingestion health.

6

One log audience for everything

Why it fails: Users, operators, defenders, and diagnostic reviewers need different levels of detail.

Better approach: Separate user messages, operational logs, security audit events, and restricted diagnostics.

7

Permanent verbose debugging

Why it fails: Temporary diagnostic detail can become long-term sensitive telemetry.

Better approach: Time-bound diagnostic settings, restrict access, review retention, and return to the approved baseline.

8

Treating every error as a security incident

Why it fails: Ordinary validation and dependency failures can overwhelm monitoring if they are not classified by purpose and impact.

Better approach: Define which events are operational, which are security-relevant, and which need escalation.

Scenario Decision Lab

Scenario Decision Lab 1 — Internal Error During Privileged Change

A fictional privileged account change fails because the record service returns an unexpected internal exception. The user is waiting, operators need to troubleshoot, and the security team must preserve the audit trail.

Scenario Decision Lab

Scenario Decision Lab 2 — Quiet Dashboard, Degraded Source

The authorization dashboard shows no events for seven minutes, but the source-health monitor reports degraded freshness while parser health remains normal.

Safe Fictional Lab

Design an Error and Logging Matrix

Use only fictional events and synthetic identifiers. Do not include real private records, credentials, tokens, internal production endpoints, or confidential logs.

1

Choose at least eight fictional error or audit events.

2

Identify the audience for each event.

3

Write a safe user-facing message where applicable.

4

Define the operational fields needed.

5

Define the security audit fields needed.

6

List forbidden sensitive values.

7

Add a correlation ID requirement for multi-service workflows.

8

Define event owner and source owner.

9

Define access and retention class.

10

Add source-health expectations.

11

Define alert or escalation conditions.

12

Assign status: Confirmed, Conditional, Unknown, or Blocked.

13

Add validation evidence.

14

Add change triggers for schema, privacy, or architecture changes.

Analyze the Evidence

Evidence Analysis: Quiet Authorization Dashboard

No authorization events are visible for seven minutes.
The source-health monitor reports freshness=DEGRADED.
Parser status is healthy.
Expected event volume for this time period is above zero.
The source later recovers and reports backlog=0.

What is the strongest evidence-based conclusion?

Advanced Challenge

Design a Privileged Audit Event Schema

Create a fictional audit schema for a high-impact account-recovery workflow that is useful to defenders without exposing secrets or unnecessary private information.

1

Event ID

2

Timestamp

3

Environment

4

Actor reference

5

Approver reference

6

Target account reference

7

Action

8

Result

9

Policy or approval reference

10

Correlation ID

11

Service source

12

Reason category

13

Forbidden fields

14

Retention class

15

Access owner

16

Source-health owner

The best schema is not the one with the most fields. It is the one that captures the evidence needed for accountability and investigation while minimizing sensitive data.

Defender Habits

A11.6 Defender Checklist

Skill Check

Seven Questions

Check Your Understanding

A11.6 Mini Quiz: Secure Error Handling and Logging

Choose your answers first. Explanations appear only after submission.

1. What is the strongest goal of secure error handling?

2. Why is a correlation ID useful?

3. Which value should never be recorded in an ordinary security log?

4. What does source-health monitoring protect against?

5. Which is the strongest user-facing message for an unexpected internal error?

6. Why should logs use data minimization?

7. A security dashboard shows no authorization events, but source freshness is degraded. What is the strongest conclusion?

Portfolio Prompt

Portfolio Build — Error Handling and Logging Design

Create the sixth artifact for your A11 Secure Software Design Assessment: a fictional error-handling and logging matrix with at least eight events. Include audience, safe user message, operational fields, security audit fields, forbidden fields, correlation requirement, owner, source owner, access class, retention class, source-health expectation, validation evidence, status, escalation rule, and change trigger.

Use synthetic identifiers and fictional events only.
Include at least one authorization decision and one privileged action.
Include one dependency failure and one source-health event.
Show how user-facing messages differ from protected diagnostics.
Include at least one event with an explicit redaction requirement.
Explain how the design supports investigations without collecting unnecessary private data.

Confidence / Readiness Reflection

Are You Ready for A11.7?

A11.7 moves to Code Review for Security. Before continuing, make sure you can identify what secure implementation reviewers should look for in error handling, logging, and evidence.

1

I can separate user-facing errors, operational logs, security audit events, and protected diagnostics.

2

I can define useful event fields without logging secrets or unnecessary private data.

3

I can explain why correlation IDs improve multi-service traceability.

4

I can evaluate source health before drawing conclusions from missing events.

5

I can define access, retention, ownership, and change triggers for logging evidence.

Portfolio Build Guide

How to Make the Logging Design Look Professional

Use event IDs

Give each important event a stable ID so requirements, code review, testing, alerts, and retention can reference it.

Separate audiences

Show the user response, operational evidence, security evidence, and diagnostic evidence separately.

Show forbidden fields

Make redaction rules explicit rather than assuming developers will know what not to log.

Use synthetic references

Use fictional actor, target, service, and correlation identifiers rather than real user data.

Show source health

Document freshness, volume, parsing, ingestion, and ownership expectations.

Show access and retention

Explain who can view the evidence and how long it should remain.

Show validation

Record how the team confirms required fields are present and forbidden values are absent.

Connect to A11

Link events back to requirements, threat-model concerns, secrets governance, and dependency workflows.

Key Takeaways

What You Should Remember

1.Secure error handling is about giving the right audience the right amount of information.
2.User messages should be useful but should not reveal unnecessary internal detail.
3.Operational logs, security audit events, and protected diagnostics serve different purposes.
4.Correlation IDs help connect distributed evidence without exposing secrets.
5.Logs should minimize sensitive data and exclude secret values entirely.
6.Source-health monitoring is necessary because missing logs can reflect a broken pipeline rather than absence of activity.
7.Authorization, privileged actions, configuration changes, and important security decisions should be auditable.
8.Retention and access are part of logging architecture, not afterthoughts.
9.The A11 logging design becomes a direct input to code review, testing, deployment, and incident response.

Lesson Safety Boundary

Use synthetic logging evidence only

Do not collect, expose, or request real credentials, tokens, private records, confidential logs, production endpoints, or other sensitive operational data. All examples in this lesson are fictional and defensive.

Lesson Complete

A11.6 Secure Error Handling and Logging Complete

You now have an error-handling and logging architecture that balances user safety, operational troubleshooting, auditability, privacy, redaction, correlation, retention, access, and source health. Next, A11.7 focuses on Code Review for Security.