Tips for safely storing data in local storage using Angular 5

How can I securely store data in local storage, such as encrypting and decrypting the local storage data to prevent manipulation by other users? If it's not possible with local storage, what are alternative methods for client-side data storage?

I've considered WebSQL, but it can also be easily manipulated by writing queries in the console.

Note: I'm looking for a solution specifically for Angular 2+.

Answer №1

Despite what another response may suggest, it is indeed possible to securely store any value on the client side. By "securely," I mean that the value is kept hidden from the client and cannot be altered. This can be achieved through storage mechanisms like localStorage, websql, or similar options. However, it is important to note that Javascript code will also be unable to access or manipulate this value, as Javascript itself is part of the client environment that you are trying to protect this data from.

If you possess a secret key on the server side, you can use it to encrypt (for confidentiality) and/or sign (for integrity) any data that is transmitted to the client. This is a common approach employed by frameworks such as Rails to manage sessions without relying on server-side storage, maintaining a relatively high level of security.

It is crucial to understand that simply encrypting a cookie on the server does not automatically authenticate its contents. It is recommended to use authenticated encryption to safeguard against potential replay attacks, for which measures like timestamps or nonces can be utilised. Furthermore, concerns such as forward secrecy should be taken into consideration if required. Ultimately, ensuring security in these scenarios can be complex, but with proper attention and effort, it is achievable.

If data is signed but not encrypted, there is still a possibility that Javascript could access it, although modifications would remain impossible.

Answer №2

It is not possible to store data on the client side that is immune to manipulation by the client.

While Angular allows for data storage in services, this information will be erased if the user decides to refresh the browser.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What happens when WebGL crashes while browsing a webpage?

One of my applications utilizes WebGL with the Three.js library, but occasionally crashes. Is there a way to catch these errors using a plain JavaScript or Three.js event? Currently, I am only listening on the window.onerror event for any errors. ...

Getting around relative paths in an Angular application hosted by NGINX

I am using NGINX to host my Angular application. The frontend is accessible at http://localhost/, and the backend can be accessed at http://localhost/api/. While most of my configuration works correctly, I am encountering an issue with a relative path in a ...

Convert an array to a string using a JavaScript function

I am encountering an issue with the code below: Every time I pass the Array to "track," I encounter an error. It seems like there might be a mismatch between passing an object and a string as input, but I am uncertain and unable to verify. for (var i = 0; ...

Styled Components do not have the ability to define :hover states

export const WatchVideoButtonWrapper = styled.div` position: absolute; bottom: 80px; right: 33px; background-color: ${(props) => props.bgColor}; color: ${(props) => props.color}; border-radius: 100px; transition: all 0.1s; ...

Choosing between creating a class with a shared instance or not

I'm curious if my class is shared across instances: for example, I have a route that looks like this: /student/:id When this route triggers the controller (simplified version): module.exports = RecalculateStudents; const recalculateActiveStudent ...

Modify the color of the designated Tab in the PRIMENG TabMenu - customize the style

Currently, I am utilizing the Primeng tab menu component and facing an issue. Unfortunately, I seem to be unable to identify a method to alter the color of the selected tab to a different shade. If anyone has any insights or suggestions on how to achieve ...

efficiently manage various nested levels of request parameters

I am configuring routes for my express app and need the following paths: /regions /regions/europe /regions/europe/france /regions/europe/france/paris Currently, I have set up individual route handlers for each path. Is there a more efficient way to ha ...

Troubleshooting ngFor in Angular 5

I'm currently working on a component that needs to display data fetched from the server. export class CommerceComponent implements OnInit { dealList; ngOnInit() { this.getDeals(); } getDeals(){ this.gatewayService.se ...

unique array that shuffles every time it is reloaded, utilizing only javascript

I have created a string array that holds 6 different classes. Whenever I click a button, a new class is generated randomly. However, the issue arises when I click the button again and get the same class instead of a new random one. Even after reloading the ...

Searching for a specific match in JSON data using React streaming technology: encountering issues with the .find method as

Having experience with functional programming in Java, I recently ventured into JavaScript. My current task involves streaming through a JSON output structured like this: { "originatingRequest": { "clientId": 1, "simulationName": "Sea ...

TypeScript - the object may potentially be 'null'

Despite receiving an error message, the program is running perfectly. https://i.sstatic.net/4NQyR.jpg var video = document.querySelector('#camera-stream'), if(!navigator.getMedia){ displayErrorMessage("Your browser doesn't have su ...

Extending an interface in TypeScript to include an Array

Can I implement a parent interface in Angular 4? export interface Devices extends Array<Device> { } The error 'Class 'DevicesModel' incorrectly implements interface 'Devices'. Property 'includes' is missing in typ ...

I am unable to run ng serve at the moment

Every time I enter ng serve it shows: Your global Angular CLI version (10.0.1) is higher than your local version (6.2.9). The local Angular CLI version will be used. To prevent this warning, use ng config -g cli.warnings.versionMismatch false. Schema va ...

Creating multiple div elements with changing content dynamically

I am facing an issue with a div named 'red' on my website where user messages overflow the 40px length of the div. To prevent this, I want to duplicate the 'red' div every time a message is sent so that the messages stay within the boun ...

Split the string in JavaScript and then count the characters to decrypt

I am currently working on a task that involves splitting a string at every space. I have successfully achieved this using .split(" "), but now I need to determine the length of each individual string. My goal is to check if a given string includes a midd ...

React Router version 6.4.5, automatic redirection upon loading the page

Seeking assistance with setting up redirects. Below are snippets of the code. index.js const router = createBrowserRouter([ { //Defining App as the root element... path: "/", loader: () => { }, element: <App/>, ...

I encountered an issue with displaying a fullcalendar within a pop-up modal

Hey there! I'm facing an issue with setting up a fullcalendar inside a bootstrap modal. When I do so, the calendar appears compressed in the top-left corner and I can't see anything. However, when I resize the screen, it suddenly displays perfect ...

Using Angular 4 to dynamically update the view when an event is emitted through Socket.io

I'm currently working on a component with the code below: ngOnInit(): void { this.siteService.socket.on("users_online_now", function(usersOnlineNow){ this.usersOnlineNow = usersOnlineNow; console.log(usersOnlineNow); }); } ...

Issue with Inline JavaScript in `href` tag not functioning correctly in Firefox

I am encountering an issue with this inline JavaScript not working in Firefox. I need to figure out how to make it function correctly in Firefox. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> ...

Tips for adjusting the horizontal position of a grid item within a map() loop

I am trying to align the text in my Timeline component from Material Ui always towards the center of the timeline. The TimelineContent contains Paper, Typography (for title and description), and an image. Currently, I have multiple TimelineContent element ...