Tips for concealing information within a JSON response using Javascript

I have a JavaScript function that retrieves card information based on its first 6 digits (BIN).

const getCardInfo = async (cardNumber, isLive = false) => {
  const binCode = cardNumber.substring(0, 6);
  const cachedData = sessionStorage.getItem(`bin_${binCode}`);

  if (cachedData) {
    const jsonParsedData = JSON.parse(cachedData);
    const cardType = jsonParsedData.type === "CREDIT" ? "Credit" : "Debit" ?? "Unknown";
    const country = jsonParsedData.country || "Unknown";
    const cardVendor = jsonParsedData.vendor || "Unknown";
    
    let cardInfoText = '';
if (isLive) {
  cardInfoText = `LIVE [${cardVendor} - ${country} - ${cardType}]`;
} else {
  cardInfoText = `[${cardVendor} - ${country} - ${cardType}]`;
}

return cardInfoText;

  }
  else {
    const response = await fetch(`https://apilink.com/api/${binCode}`);
    const jsonParsedData = await response.json();
    if (!jsonParsedData.result) {
      return "UNKNOWN";
    }

    const cardType = jsonParsedData.data.type === "CREDIT" ? "Credit" : "Debit" ?? "Unknown";
    const country = jsonParsedData.data.country || "Unknown";
    const cardVendor = jsonParsedData.data.vendor || "Unknown";

    // Store information in cache only if it does not exist already
    const cachedData = sessionStorage.getItem(`bin_${binCode}`);
    if (!cachedData) {
      sessionStorage.setItem(`bin_${binCode}`, JSON.stringify(jsonParsedData.data));
    }

    let cardInfoText = '';
    if (isLive) {
      cardInfoText = `- LIVE [${cardVendor} - ${country} - ${cardType}]`;
    } else {
      cardInfoText = `[${cardVendor} - ${country} - ${cardType}]`;
    }

    return cardInfoText;
  }
};

The function works fine, as confirmed by the browser's network section under "Preview" and "response":

{"bin":542343,"vendor":"MASTERCARD","type":"CREDIT","level":"STANDARD","bank":"BANCA COMERCIALA CARPATICA S.A.","country":"ROMANIA","countryInfo":{"name":"Romania","emoji":"🇷🇴","unicode":"U+1F1F7 U+1F1F4","code":"RO"}}}

Instead of displaying all this data, you just want to show cardNumber - LIVE. How can you achieve this without much experience?

Answer â„–1

Mitigating the Visibility of JSON Results in the Network Tab

It can be challenging to prevent the Network tab from displaying JSON results, as this is typically beyond a programmer's control. To avoid end-users seeing sensitive information in the console, the server must be configured not to send it.

While it may seem tempting to invest significant effort into hiding this data, remember that your code is ultimately responsible for transmitting the BIN code.

Given that Javascript has access to the BIN code, it's crucial to operate under the assumption that malicious users could potentially compromise your code and reveal sensitive information.

Even if you opt to encrypt the BIN code and make changes to the API link to support encrypted data, there is still a risk that a determined user could modify the Javascript to access the original unencrypted BIN code.

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 is the best way to create a JavaScript animation for altering the width of a div element?

Need help with creating a dynamic poll chart based on YES and NO votes? Check out this project where you can visually see the results by clicking HERE. Looking to add some animation effects to your poll? You can achieve a smooth transition using CSS with ...

Menu becomes sticky too quickly on iOS Safari and Chrome, jumping to fixed position prematurely

Feeling frustrated with this seemingly straightforward code challenge. My sticky menu is causing me headaches on iOS devices, particularly the iPhone 6 running the latest iOS. It seems like the menu jumps into its fixed position too early, leading me to be ...

Conflicting configurations in VS Code causing issues

Currently making adjustments to my JSON settings and everything is functioning correctly, however, I keep encountering this persistent error: "Expected comma jsonc(514)" Here's a snippet of my code that's causing the issue: "css.li ...

How can I implement a single Ajax call to load content from various pages and display it

This code facilitates an ajax call to dynamically change the content of a div in the main page without requiring a full page reload: function ajaxcall() { $.ajax({ type: "POST", url: "/create.php", success: function( returnedDa ...

Submitting forms through Vanilla JavaScript using AJAX

Can anyone assist me in implementing an AJAX form submission using Vanilla JavaScript instead of jQuery? I have the following jQuery code that needs to be converted: document.addEventListener('DOMContentLoaded', function() { document.querySelec ...

Steps for assigning an id to an element using Selenium

When using Selenium, you have the ability to access the underlying DOM of the browser being manipulated through IWebElement instances. For example: IWebElement domWrapper = driver.FindElement(By.Name("q")); But what if you have the "domWrapper" instance ...

Having trouble with Django's submit POST method for creating objects

Latest Updates: I have successfully implemented a feature where the page does not reload upon clicking the submit button. To achieve this, I filled out the form and inspected the page source code. The form structure was as follows: https://i.sstatic.net/ ...

Prevent unauthorized AJAX requests from external sources within the Node application

I am looking for a way to prevent AJAX requests from being made outside of my application. I need to ensure that the response is not sent when the AJAX request is initiated from external sources, even if the URL is copied and pasted into a browser. My te ...

Undefined React custom hooks can be a tricky issue to troub

Just delving into the world of React and trying to wrap my head around custom hooks, but I keep hitting roadblocks. Here's the latest hurdle that I'm facing, hoping for some guidance. I'm taking a step-by-step approach to creating a functio ...

Traversing through JSON data in Flutter using iterable

Hey everyone, I'm facing an issue that I need help with. I recently made a successful get request through an API using Flutter. The problem I have is related to a 'mentee id' list that I received from the previous screen. Here is what it loo ...

Navigating a complex web: Djikstra algorithm applied to a multigraph

Encountering an issue while implementing Dijkstra's algorithm on a multigraph. The graph consists of nodes representing stops with information and connections to other stops (edges). However, the challenge arises when there are multiple bus options be ...

The AppBar in a secondary color is looking sleek and modern with the Select component

I am currently utilizing version 33 of material-ui-next: import * as mui from 'material-ui'; Within a component, I have an AppBar featuring a ToolBar and a Select: render() { return ( <mui.AppBar color="secondary"> <mui.To ...

Tips for preserving line breaks when sending a message through the mail

Hi, I'm currently facing an issue: I am trying to send text from a textarea using POST to a PHP script that will write it to a file and display it on the website. However, when I do this, the line breaks disappear and the displayed text ends up lookin ...

Trouble handling Ajax response

I have two JSP files described below. The parent JSP page contains a Select dropdown box with two options. Another JSP file, dispTable.jsp, displays select boxes inside a table. If the user selects "one" from the dropdown in the parent.jsp page, I want ...

"Exploring the world of JavaScript, Ajax, PHP parser errors, and the process of obtaining post data

Having an issue with the AJAX functionality in my game.php file. Despite my efforts to refresh .refre, I keep encountering a "parsererror" message. The jsonString variable is created using JSON.stringify(object). <div class="refre"></div> < ...

Creating a JSON array dynamically and appending elements to it during runtime

Is there a way to dynamically create multiple arrays at runtime in a program and have the ability to add data to a specific array when needed? button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEven ...

Sorting information in the React Native Section List

Working with React Native's SectionList and filtering data: data: [ { title: "Asia", data: ["Taj Mahal", "Great Wall of China", "Petra"] }, { title: "South America", data: ["Machu Picchu", "Christ the Redeemer", "C ...

DANGEROUS EVALUATION: Tips for Safe Replacement

Looking for a safer alternative to the code below which utilizes eval. The script creates pop-up windows based on different classes. /* exported popup_default , popup_help , popup_sitemap , popup_footerlinks */ var matchClass = ['popup_default' ...

Error: Found an unconventional token "e" in JSON data at position 1 during parsing in JSON.parse function

Is there a way to retrieve a string value by calling an API in Angular? Here is my approach: Service file - public getRespondDashboardUrl(): Observable<any> { return this.http.get(`ref/RespondDashboardUrl`); } Component File respondDashboar ...

Is there a way to have a span update its color upon clicking a link?

I have 4 Spans and I'm looking to create an interactive feature where clicking a link in a span changes the color of that span. Additionally, when another link in a different span is clicked, the color of that span changes while reverting the previous ...