Skip to content

Commit

Permalink
Merge pull request #291 from ajinkyapandetekdi/25-feb-1.4.0
Browse files Browse the repository at this point in the history
Issue #236402 Secure all Localstorage Value for VAPT fixes
  • Loading branch information
gouravmore authored Mar 4, 2025
2 parents 267acea + 4bd9c72 commit 64abb16
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 124 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"canvas-confetti": "^1.9.2",
"character-error-rate": "^1.1.4",
"classnames": "^2.3.1",
"crypto-js": "^4.2.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.1",
Expand Down
46 changes: 23 additions & 23 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,32 @@ const App = () => {
};
}, []);

useEffect(() => {
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response && error.response.status === 401) {
if (error?.response?.data?.error === "Unauthorized") {
if (
localStorage.getItem("contentSessionId") &&
process.env.REACT_APP_IS_APP_IFRAME === "true"
) {
window.parent.postMessage(
{
message: "Unauthorized",
}, window?.location?.ancestorOrigins?.[0] || window.parent.location.origin
);
} else {
localStorage.clear();
sessionStorage.clear();
navigate("/login");
}
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response && error.response.status === 401) {
if (error?.response?.data?.error === "Unauthorized") {
if (
localStorage.getItem("contentSessionId") &&
process.env.REACT_APP_IS_APP_IFRAME === "true"
) {
window.parent.postMessage(
{
message: "Unauthorized",
},
window?.location?.ancestorOrigins?.[0] ||
window.parent.location.origin
);
} else {
localStorage.clear();
sessionStorage.clear();
navigate("/login");
}
}
return Promise.reject(error);
}
);
}, []);
return Promise.reject(error);
}
);

return (
<StyledEngineProvider injectFirst>
Expand Down
15 changes: 7 additions & 8 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,8 @@ const Assesment = ({ discoverStart }) => {
// const level = getLocalData('userLevel');
// setLevel(level);
setLocalData("lang", lang);
dispatch(setVirtualId(localStorage.getItem("virtualId")));
let contentSessionId = localStorage.getItem("contentSessionId");
localStorage.setItem("sessionId", contentSessionId);
setLocalData("sessionId", contentSessionId);
// const TOKEN = localStorage.getItem("apiToken");
// let virtualId;
// if (TOKEN) {
Expand All @@ -589,19 +588,19 @@ const Assesment = ({ discoverStart }) => {
const usernameDetails = await fetchVirtualId(username);
const getMilestoneDetails = await getFetchMilestoneDetails(lang);

localStorage.setItem(
setLocalData(
"getMilestone",
JSON.stringify({ ...getMilestoneDetails })
);
setLevel(getMilestoneDetails?.data?.milestone_level?.replace("m", ""));
let session_id = localStorage.getItem("sessionId");
let session_id = getLocalData("sessionId");

if (!session_id) {
session_id = uniqueId();
localStorage.setItem("sessionId", session_id);
setLocalData("sessionId", session_id);
}

localStorage.setItem("lang", lang || "ta");
setLocalData("lang", lang || "ta");
if (
process.env.REACT_APP_IS_APP_IFRAME !== "true" &&
localStorage.getItem("contentSessionId") !== null
Expand All @@ -622,7 +621,7 @@ const Assesment = ({ discoverStart }) => {
(async () => {
const language = lang;
const getMilestoneDetails = await getFetchMilestoneDetails(language);
localStorage.setItem(
setLocalData(
"getMilestone",
JSON.stringify({ ...getMilestoneDetails })
);
Expand All @@ -633,7 +632,7 @@ const Assesment = ({ discoverStart }) => {

if (!sessionId || sessionId === "null") {
sessionId = uniqueId();
localStorage.setItem("sessionId", sessionId);
setLocalData("sessionId", sessionId);
}

if (
Expand Down
2 changes: 1 addition & 1 deletion src/components/AssesmentEnd/AssesmentEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AssesmentEnd = () => {
let sessionId = getLocalData("sessionId");
if (!sessionId) {
sessionId = uniqueId();
localStorage.setItem("sessionId", sessionId);
setLocalData("sessionId", sessionId);
}
if (
process.env.REACT_APP_IS_APP_IFRAME !== "true" &&
Expand Down
16 changes: 3 additions & 13 deletions src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import elephant from "../../assets/images/elephant.svg";
import {
callConfetti,
getLocalData,
sendTestRigScore,
setLocalData,
} from "../../utils/constants";
import WordsOrImage from "../Mechanism/WordsOrImage";
Expand Down Expand Up @@ -112,17 +113,6 @@ const SpeakSentenceComponent = () => {
//eslint-disable-next-line
}, [voiceText]);

const send = (score) => {
if (process.env.REACT_APP_IS_APP_IFRAME === "true") {
window.parent.postMessage(
{
score: score,
message: "all-test-rig-score",
}, window?.location?.ancestorOrigins?.[0] || window.parent.location.origin
);
}
};

const handleNext = async () => {
setIsNextButtonCalled(true);
setEnableNext(false);
Expand Down Expand Up @@ -164,7 +154,7 @@ const SpeakSentenceComponent = () => {
console.error("Error adding points:", error);
}
} else {
send(5);
sendTestRigScore(5);
// setPoints(localStorage.getItem("currentLessonScoreCount"));
}

Expand Down Expand Up @@ -279,7 +269,7 @@ const SpeakSentenceComponent = () => {
setTotalSyllableCount(resPagination?.totalSyllableCount);
setCurrentCollectionId(sentences?.collectionId);
setAssessmentResponse(resAssessment);
localStorage.setItem("storyTitle", sentences?.name);
setLocalData("storyTitle", sentences?.name);
quesArr = [...quesArr, ...(resPagination?.data || [])];
setQuestions(quesArr);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/content/contentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const API_BASE_URL_CONTENT_SERVICE =
process.env.REACT_APP_CONTENT_SERVICE_APP_HOST;

const getHeaders = () => {
const token = getLocalData("apiToken");
const token = localStorage.getItem("apiToken");
return {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json"
}
"Content-Type": "application/json",
},
};
};

Expand Down
8 changes: 4 additions & 4 deletions src/services/learnerAi/learnerAiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getVirtualId } from "../userservice/userService";
const API_LEARNER_AI_APP_HOST = process.env.REACT_APP_LEARNER_AI_APP_HOST;

const getHeaders = () => {
const token = getLocalData("apiToken");
const token = localStorage.getItem("apiToken");
return {
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -33,7 +33,7 @@ export const getContent = async (criteria, lang, limit, options = {}) => {
};

export const getFetchMilestoneDetails = async (lang) => {
if (getLocalData("apiToken")) {
if (localStorage.getItem("apiToken")) {
try {
const response = await axios.get(
`${API_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}?language=${lang}`,
Expand All @@ -53,7 +53,7 @@ export const fetchGetSetResult = async (
currentCollectionId,
totalSyllableCount
) => {
const session_id = localStorage.getItem("sessionId");
const session_id = getLocalData("sessionId");
const lang = getLocalData("lang");

try {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const getSetResultPractice = async ({
contentType: currentContentType,
session_id: sessionId,
totalSyllableCount: totalSyllableCount,
language: localStorage.getItem("lang"),
language: getLocalData("lang"),
is_mechanics: mechanism && mechanism?.id ? true : false,
},
getHeaders()
Expand Down
8 changes: 4 additions & 4 deletions src/services/orchestration/orchestrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const API_BASE_URL_ORCHESTRATION =
process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST;

const getHeaders = () => {
const token = getLocalData("apiToken");
const token = localStorage.getItem("apiToken");
return {
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -46,7 +46,7 @@ export const fetchUserPoints = async () => {
};

export const addPointer = async (points, milestone) => {
const sessionId = localStorage.getItem("sessionId");
const sessionId = getLocalData("sessionId");
const lang = getLocalData("lang");

try {
Expand All @@ -72,8 +72,8 @@ export const createLearnerProgress = async (
milestoneLevel,
totalSyllableCount
) => {
const sessionId = localStorage.getItem("sessionId");
const language = localStorage.getItem("lang");
const sessionId = getLocalData("sessionId");
const language = getLocalData("lang");

try {
const requestBody = {
Expand Down
3 changes: 2 additions & 1 deletion src/services/telementryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CsTelemetryModule } from "@project-sunbird/client-services/telemetry";

import { uniqueId } from "./utilService";
import { jwtDecode } from "../../node_modules/jwt-decode/build/cjs/index";
import { getLocalData } from "../utils/constants";

let startTime; // Variable to store the timestamp when the start event is raised
let contentSessionId;
Expand Down Expand Up @@ -266,7 +267,7 @@ export const getEventOptions = () => {
},
{ id: playSessionId, type: "PlaySession" },
{ id: userId, type: userType },
{ id: localStorage.getItem("lang") || "ta", type: "language" },
{ id: getLocalData("lang") || "ta", type: "language" },
{ id: userDetails?.school_name, type: "school_name" },
{
id: userDetails?.class_studying_id,
Expand Down
25 changes: 13 additions & 12 deletions src/utils/Badwords.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import wordLists from '../Badwords/badWords.json'
import wordLists from "../Badwords/badWords.json";
import { getLocalData } from "./constants";

export const checkBadWord = userInput => {
const lang_code = localStorage.getItem('lang') || 'ta';
export const checkBadWord = (userInput) => {
const lang_code = getLocalData("lang") || "ta";
const words = wordLists[lang_code];

if (!words || !Array.isArray(words)) {
Expand All @@ -12,20 +13,20 @@ export const checkBadWord = userInput => {
return words.includes(cleanedInput);
};

export const filterBadWords = input => {
let texttemp = input.replace(/[.,|!?']/g, '');
export const filterBadWords = (input) => {
let texttemp = input.replace(/[.,|!?']/g, "");
const wordsToFilter = texttemp.toLowerCase().split(/\s+/); // Split the input into an array of words
const filteredWords = wordsToFilter.map(word => {
const filteredWords = wordsToFilter.map((word) => {
if (checkBadWord(word)) {
return `${word[0]}*****${word[word.length-1]}`; // Replace bad words with ****
return `${word[0]}*****${word[word.length - 1]}`; // Replace bad words with ****
}
return word;
});

return filteredWords.join(' '); // Join the array back into a string
return filteredWords.join(" "); // Join the array back into a string
};

export const isProfanityWord=()=>{
let isProfanity = localStorage.getItem('voiceText') || '';
return isProfanity.includes("*****")
}
export const isProfanityWord = () => {
let isProfanity = localStorage.getItem("voiceText") || "";
return isProfanity.includes("*****");
};
2 changes: 1 addition & 1 deletion src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function VoiceAnalyser(props) {
sub_session_id,
contentId,
contentType,
mechanics_id: localStorage.getItem("mechanism_id") || "",
mechanics_id: getLocalData("mechanism_id") || "",
};

if (props.selectedOption) {
Expand Down
49 changes: 45 additions & 4 deletions src/utils/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 64abb16

Please sign in to comment.