smartyfy.mrindigi.com

Web Development Pro | Lesson 049 | Privacy and the Backend Boundary

Web Development Pro · Lesson 49 of 60

Module 5: Quality, accessibility, and security

In this lesson

Prerequisites and learning outcomes

Complete lesson 48 first. This lesson builds on data minimization and real form services. By the end, you can separate safe static demos from server-side validation, secrets, and delivery. Plan 10–15 minutes for the core explanation and additional time for the worked practice.

Ask whether the data is needed at all

A useful frontend does not need to collect everything it could collect. The Community Learning Hub helps visitors read public workshop information and narrow a directory. That goal requires event titles, categories, dates, and venues. It does not require visitors' names, email addresses, ages, or attendance histories.

Data minimization starts before choosing a form field. For each proposed value, state the purpose, who needs it, where it goes, and how long it remains. If you cannot explain why a field helps the task, remove it from the design. Fewer collected values mean fewer opportunities for accidental exposure and simpler maintenance.

Draw the static-demo boundary clearly

This course's demo can filter public records and remember a harmless display preference. It cannot genuinely reserve a seat, verify identity, deliver a confirmation email, or enforce a capacity limit across visitors. Those actions need a backend or an explicitly chosen service with suitable validation and authorization.

A button saying “Booked” would mislead someone if all it did was change local text. Use wording such as “Practice selection” or “Preview only” and explain that no registration occurs. The sample has a topic selector and a non-submitting button, with no name or email field and no external endpoint.

<label for="topic">Practice topic</label>
<select id="topic">
  <option value="repair">Repair</option>
  <option value="gardening">Gardening</option>
</select>
<button id="preview" type="button">Preview locally</button>
<p id="message" role="status"></p>

There is no form submission to fall back to when JavaScript is absent. The static text explains the limitation, and the button only updates a local message when the module runs. This avoids relying solely on preventDefault to stop a real submission.

Keep secrets outside browser-delivered files

Anything sent to a visitor's browser should be treated as available to that visitor. A secret embedded in JavaScript, HTML, JSON, a source map, or a supposedly hidden configuration object is not protected by obscurity. Minification changes readability, not the fundamental visibility of the value.

Some build tools replace environment variables with literal values in a frontend bundle. Naming a variable SECRET does not change that result. Public configuration, such as a harmless feature flag, can belong in the frontend. Credentials that authorize privileged operations belong in an appropriate backend or secure service design.

Do not put real credentials into this course's examples or test fixtures. Use clearly fictional placeholders when explaining configuration. If an actual secret is exposed, removing it from the latest file is not enough; copies may remain in history or caches, and the responsible owner needs an appropriate revocation or rotation process.

Treat saved preferences as optional and recoverable

A preference such as comfortable versus compact spacing can be stored locally if the product has a clear reason. It is not an identity system. The browser may block storage, clear it, or contain malformed data. The interface should work with safe defaults when reading or writing fails.

The supplied preference helper stores only a version and density value under one application-specific key. It rejects unknown versions and values. Clearing the preference removes only that key rather than clearing the entire origin's storage, which could destroy unrelated applications' data.

Local storage is persistent client-side storage accessible to scripts on the origin. It is not a secure vault and is not automatically private from everyone using the device. Avoid saving attendee details, passwords, or tokens there as part of this beginner demo. A privacy statement should accurately describe what the actual product stores.

Understand what a real backend would add

A genuine booking endpoint must independently validate accepted fields, authenticate or otherwise identify the action as required, authorize it, enforce capacity consistently, and handle duplicates and errors. It needs a reliable source of truth shared across visitors. Browser validation cannot enforce these rules because requests can bypass the interface.

The service also needs an explicit delivery and retention design if it collects contact information. Who receives a message? What provider handles it? When is the data deleted? What happens when delivery fails? These are product and operational decisions, not details solved by attaching fetch to a button.

Privacy obligations depend on the actual service and jurisdiction. This engineering example does not certify legal compliance.

Review URLs, logs, and third-party requests

Do not place personal details in query parameters merely because URLSearchParams makes encoding easy. URLs can appear in browser history, copied links, server logs, and referrer information under applicable policies. Shareable filters should describe public directory choices, not a visitor's private circumstances.

Likewise, logging every form value can create a second, poorly controlled data store. Keep diagnostics bounded to what is needed. A failure code and component name may be enough without retaining the user's full input. External analytics, fonts, widgets, and error-reporting services can also create requests to other organizations.

The sample makes no third-party requests. That is a property of these files and their intended local use, not a promise that every future host has no logging. Hosting infrastructure may record requests, so the release review must examine the actual provider and configuration before making public privacy claims.

Make the next safe step explicit

The deliverable is a local preview that clearly says nothing was submitted, plus a recoverable non-sensitive preference example. Run the Node tests with a storage double to verify valid, corrupt, unavailable, and clear behavior. The double does not test real browser persistence or device policies.

Before adding a real registration feature, write the proposed data flow and choose the responsible service owner. Ask for the necessary approvals and security review rather than quietly turning a practice form into a live collection endpoint. Expanding the product's responsibilities should be a deliberate decision.

Worked practice

Worked exercise 1: Remove an unnecessary field

Task: A directory filter asks for a visitor's email. Worked answer: remove the field because searching public event titles does not need contact information. If a separate subscription feature is later requested, define its purpose and service explicitly rather than coupling it to basic search.

Worked exercise 2: Repair a fake booking message

Task: A local click displays “You are registered.” Worked answer: change it to “Practice selection only; nothing was submitted.” A local UI update cannot guarantee a reservation or shared capacity change. The wording should match the actual behavior.

Worked exercise 3: Clear a preference safely

Task: A reset button calls localStorage.clear(). Worked answer: remove only the application's documented preference key and restore the default interface state. Clearing all origin storage is broader than resetting one harmless preference and can affect unrelated data.

Knowledge check

Question 1

What data does public title search require? A) A visitor identity record so a public title can be compared. B) A stored history of past searches for every visitor. C) The public records and search choice. D) A contact email before showing an unpersonalized result.

Check question 1: answer and explanation

Answer: C. The task can work without collecting personal identity.

Question 2

Where can a frontend secret be kept safely merely by naming it SECRET? A) In a bundled variable. B) Nowhere in publicly delivered code on that basis. C) In a hidden input. D) In a minified comment.

Check question 2: answer and explanation

Answer: B. Browser-delivered values remain accessible regardless of naming or minification.

Question 3

What should happen when optional storage fails? A) The directory remains usable with defaults. B) Search remains disabled until the preference can be saved. C) The code silently writes the same preference to another storage system. D) All origin storage is erased before retrying.

Check question 3: answer and explanation

Answer: A. A preference should not become a critical dependency.

Question 4

What makes a reservation genuine? A) Disabling the booking button after one click. B) Writing the request into persistent local storage. C) Displaying an optimistic message alone. D) A suitable service enforcing the shared operation and reporting its result.

Check question 4: answer and explanation

Answer: D. A browser-only demonstration cannot coordinate real capacity.

Question 5

Why avoid private data in shareable URLs? A) URL encoding prevents every browser from retaining the value. B) HTTPS prevents the destination server from recording query parameters. C) URLs can spread through history, logs, and copied links. D) Using URLSearchParams makes the resulting URL confidential.

Check question 5: answer and explanation

Answer: C. Encoding does not make a value private.

Sources and further reading