Merged PR 2315: Auth stabilistatiion and hardening

Related work items: #23020
This commit is contained in:
Robert Bond
2026-05-14 08:55:49 +00:00
parent d295a507ac
commit d0b2fd077a
41 changed files with 1462 additions and 418 deletions
+7 -7
View File
@@ -140,7 +140,7 @@ const Home = (props) => {
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
const { query, req } = ctx;
getIP(req);
const searchResultsObj = await getAddressSearch(query);
const searchDetailsObj = searchResultsObj;
@@ -168,14 +168,14 @@ export const getServerSideProps = wrapper.getServerSideProps(
const [accountDetails, searchResultsObj, watchedCases] =
await Promise.all([
await getPersonalAccount(loggedInUser),
await getAdvancedSearch(query),
await getWatchedCases(loggedInUser)
getPersonalAccount(loggedInUser),
getAdvancedSearch(query),
getWatchedCases(loggedInUser)
]);
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
await getSearchDetails(searchResultsObj),
await getDetails(watchedCases, "myWatchedCases")
getSearchDetails(searchResultsObj),
getDetails(watchedCases, "myWatchedCases")
]);
store.dispatch(setAccountDetails(accountDetails));
@@ -203,7 +203,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
const getDetails = (resultsObj, detailsType) => {
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
const detailsObj = resultsObj.map((searchDetail) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"
+87 -19
View File
@@ -2,7 +2,7 @@ import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../actions/core/logger";
import { consoleLogger, getIP } from "../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
@@ -46,7 +46,6 @@ const Home = (props) => {
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
return (
@@ -79,44 +78,98 @@ const Home = (props) => {
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
const { query, req } = ctx;
getIP(req);
console.log("query-", query);
//console.log("search array:", Object.entries(query));
const { cookies } = req;
const showLoginCheck = process.env.SHOWLOGIN || false;
let thisSession = await getSession(ctx);
let loggedInUser = await getPortalLogin(thisSession.user.email);
if (!thisSession) {
console.log("not has sesssion.......");
consoleLogger({
name: "MyPortalAdvancedSearchResultsAuthGuard",
reasonCode: "NO_SESSION",
message:
"advancedsearchresults loader missing session; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
} else {
}
if (!thisSession?.user?.email || !thisSession?.user?.id) {
consoleLogger({
name: "MyPortalAdvancedSearchResultsAuthGuard",
reasonCode: "NO_SESSION_USER",
message:
"advancedsearchresults loader missing session user identity; redirecting to signin",
hasSessionUserEmail: !!thisSession?.user?.email,
hasSessionUserId: !!thisSession?.user?.id
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
let loggedInUser;
try {
const loggedInUserLookup = await getPortalLogin(
thisSession.user.email
);
loggedInUser = loggedInUserLookup?.value?.[0]?.contactid;
} catch (error) {
consoleLogger({
name: "MyPortalAdvancedSearchResultsAuthGuard",
reasonCode: "UPSTREAM_FAILURE",
message:
"advancedsearchresults loader portal login lookup failed; redirecting to signin",
error: error?.message
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
if (!loggedInUser) {
consoleLogger({
name: "MyPortalAdvancedSearchResultsAuthGuard",
reasonCode: "CONTACT_LOOKUP_FAILED",
message:
"advancedsearchresults loader missing CRM contact id; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
try {
thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id));
loggedInUser = await getPortalLogin(thisSession.user.email);
loggedInUser = loggedInUser.value[0].contactid;
const [accountDetails, watchedCases] = await Promise.all([
await getPersonalAccount(loggedInUser),
await getWatchedCases(loggedInUser)
getPersonalAccount(loggedInUser),
getWatchedCases(loggedInUser)
]);
console.log(accountDetails);
const [watchedCasesDetails] = await Promise.all([
await getDetails(watchedCases, "myWatchedCases")
]);
const watchedCasesDetails = await getDetails(
watchedCases,
"myWatchedCases"
);
const showLoginCheck = process.env.SHOWLOGIN || false;
const showReps = process.env.SHOWREPRESENTATIONS || false;
@@ -127,7 +180,22 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setSearch(Object.entries(query)));
store.dispatch(setLoggedInUserId(loggedInUser));
} catch (error) {
consoleLogger({
name: "MyPortalAdvancedSearchResultsAuthGuard",
reasonCode: "UPSTREAM_FAILURE",
message:
"advancedsearchresults loader dependency failure; redirecting to signin",
error: error?.message
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
return {
props: {
showLoginCheck: showLoginCheck
@@ -139,7 +207,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
const getDetails = (resultsObj, detailsType) => {
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
const detailsObj = resultsObj.map((searchDetail) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"
+65 -112
View File
@@ -2,7 +2,7 @@ import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../../actions/core/logger";
import { consoleLogger, getIP } from "../../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
@@ -61,17 +61,10 @@ import ServiceBanner from "../../../components/myportal/servicebanner";
import TimeOut from "../../../components/timeout";
const CaseHome = (props) => {
const {
footerLinks,
pages,
setSearchResults,
setSearchDetails,
searchResultsObj
} = props;
let { t, lang } = useTranslation();
const { footerLinks } = props;
useTranslation();
const router = useRouter();
const { locale } = router;
const { ticketnumber } = router.query;
return (
@@ -94,9 +87,6 @@ const CaseHome = (props) => {
props={props}
myCases={props.myCases.myCases}
myCasesDetails={props.myCases.myCasesDetails}
// directSearchResultsObj={
// props.searchResultsObj.searchResultsObj
// }
searchResultsObj={
props.searchResultsObj.searchResultsObj
}
@@ -150,28 +140,44 @@ const CaseHome = (props) => {
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
const { query, req } = ctx;
getIP(req);
const { cookies } = req;
console.log(cookies);
console.log("the query :", query.ticketnumber);
console.log("viewkey: " + (query.hasOwnProperty("key") ? "yes" : "no"));
consoleLogger({
name: "MyPortalCaseTicketLoaderStart",
message: "myportal case ticket loader invoked",
hasTicketNumber: !!query?.ticketnumber,
hasViewKey: Object.prototype.hasOwnProperty.call(query, "key")
});
const showLoginCheck = process.env.SHOWLOGIN || false;
let thisSession = await getSession(ctx);
const thisSession = await getSession(ctx);
let loggedInUser = {};
if (thisSession) {
console.log(" has sesssion.......");
[loggedInUser] = await Promise.all([
await getPortalLogin(thisSession.user.email)
]);
loggedInUser = await getPortalLogin(thisSession.user.email);
loggedInUser = loggedInUser.value[0].contactid;
loggedInUser = loggedInUser?.value?.[0]?.contactid;
if (!loggedInUser) {
consoleLogger({
name: "MyPortalCaseTicketMissingContact",
message:
"myportal case ticket loader missing CRM contact id; redirecting to signin",
hasSessionEmail: !!thisSession?.user?.email
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
} else {
console.log("not has sesssion.......");
consoleLogger({
name: "MyPortalCaseTicketMissingSession",
message:
"myportal case ticket loader missing session; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
@@ -191,22 +197,24 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setLoggedInUserId(loggedInUser));
let developmentQuery = query.ticketnumber;
const developmentQuery = query.ticketnumber;
const pattern = /CAS-\d{5}-[A-Z0-9]{6}/;
const match = query.ticketnumber.match(pattern);
if (match) {
console.log("Match found!", match[0]);
} else {
console.log("No match.");
if (!match) {
consoleLogger({
name: "MyPortalCaseTicketUnexpectedFormat",
message: "ticketnumber does not match CAS expected format",
hasTicketNumber: !!query?.ticketnumber
});
}
const searchResultsObj = await getBasicSearch(developmentQuery);
const searchDetailsObj = await getSearchDetails(searchResultsObj);
var eventsObj = {};
var mediaObj = {};
let eventsObj = {};
let mediaObj = {};
if (searchResultsObj.value[0].pinswg_appealcasetype == 846040002) {
eventsObj = await getSIPSEvents(
@@ -220,25 +228,16 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setMediaDetails(mediaObj));
}
//console.log(
// "\n======================================\n",
// searchResultsObj,
// "\n======================================\n"
// );
//console.log(
// "\n======================================\n",
// searchDetailsObj[0],
// "\n======================================\n"
// );
store.dispatch(setSearch(developmentQuery));
// console.log(
// searchResultsObj["@odata.count"] > 1 ||
// searchResultsObj["@odata.count"] < 1
// );
if (searchResultsObj["@odata.count"] < 1) {
consoleLogger({
name: "MyPortalCaseTicketSearchNotFound",
message:
"myportal case ticket loader search count < 1; redirecting to 404",
ticketnumber: query?.ticketnumber
});
return {
redirect: {
destination: "/404",
@@ -247,6 +246,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
};
} else {
if (searchResultsObj["@odata.count"] > 1) {
consoleLogger({
name: "MyPortalCaseTicketSearchAmbiguous",
message:
"myportal case ticket loader search count > 1; redirecting to 404",
ticketnumber: query?.ticketnumber,
count: searchResultsObj["@odata.count"]
});
return {
redirect: {
//destination: "/dns-not-found",
@@ -255,7 +261,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
}
};
} else {
if (query.hasOwnProperty("key")) {
if (Object.prototype.hasOwnProperty.call(query, "key")) {
let whichViewKey = query.key;
switch (whichViewKey) {
@@ -268,42 +274,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
);
break;
case "watchedCases":
// const watchedCases = await getWatchedCases(
// loggedInUser
// );
// let showWatchedCases = (submittedArr) => {
// const required = submittedArr.value.filter(
// (el) => {
// return (
// el.pinswg_representationsubmitted ==
// null
// );
// }
// );
// let newObj = {};
// return Object.assign(newObj, {
// "@odata.count": required.length,
// "value": required,
// });
// };
// let filteredWatchedCases =
// showWatchedCases(watchedCases);
// const watchedCasesDetails = await getDetails(
// filteredWatchedCases,
// "myWatchedCases"
// );
// store.dispatch(
// setWatchedCases(filteredWatchedCases)
// );
// store.dispatch(
// setWatchedCasesDetails(watchedCasesDetails)
// );
store.dispatch(
setCurrentView({
"viewName": "Watched Cases",
@@ -362,19 +332,19 @@ export const getServerSideProps = wrapper.getServerSideProps(
}
const watchedCases = await getWatchedCases(loggedInUser);
let showWatchedCases = (submittedArr) => {
const showWatchedCases = (submittedArr) => {
const required = submittedArr.value.filter((el) => {
return el.pinswg_representationsubmitted == null;
});
let newObj = {};
const newObj = {};
return Object.assign(newObj, {
"@odata.count": required.length,
"value": required
});
};
let filteredWatchedCases = showWatchedCases(watchedCases);
const filteredWatchedCases = showWatchedCases(watchedCases);
const watchedCasesDetails = await getDetails(
filteredWatchedCases,
@@ -415,9 +385,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
(el) => el.pinswg_representationsubmitted != null
);
const [mySubmittedRepsDetails] = await Promise.all([
getDetails(mySubmittedReps, "mySubmittedReps")
]);
const mySubmittedRepsDetails = await getDetails(
mySubmittedReps,
"mySubmittedReps"
);
store.dispatch(setMySubmittedReps(mySubmittedReps));
store.dispatch(
@@ -425,9 +396,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
);
}
}
//console.log(searchResultsObj);
//console.log(loggedInUser);
return {
props: {
searchResultsObj: {
@@ -455,7 +423,7 @@ const getDetails = (resultsObj, detailsType) => {
detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value;
if (detailsType == "myRepresentations") {
const repsObj = resultsObj.map((searchDetail, index) => {
resultsObj.map((searchDetail) => {
detailsArr.push(
getCase(searchDetail["incidentID"]).then((data) => {
let caseID = "";
@@ -488,7 +456,7 @@ const getDetails = (resultsObj, detailsType) => {
});
}
const detailsObj = resultsObj.map((searchDetail, index) => {
resultsObj.map((searchDetail) => {
let caseID = "";
switch (detailsType) {
@@ -512,25 +480,17 @@ const getDetails = (resultsObj, detailsType) => {
caseID = searchDetail.pinswg_title;
}
//console.log(detailsType, " case id : ", caseID);
searchDetail.pinswg_appealcasetype != null &&
detailsArr.push(
getPortalModuleDetails(
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
.LogicalCollectionName,
caseID
// detailsType != "myWatchedCases"
// ? searchDetail.ticketnumber
// : searchDetail[
// "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
// ]
)
);
});
let detArr = Promise.all(detailsArr);
console.log(detArr);
const detArr = Promise.all(detailsArr);
return detArr;
};
@@ -539,7 +499,6 @@ const mapStateToProps = (state) => {
accountDetails: state.accountDetails,
currentView: state.currentView,
search: state.search,
//searchResultsObj: state.searchResultsObj,
documentDetailsObj: state.searchResultsObj.documentDetailsObj,
formData: state.formData,
appealType: state.appealType,
@@ -557,12 +516,6 @@ const mapDispatchToProps = (dispatch) => {
setCurrentReference: (currentReference) => {
dispatch(setCurrentReference(refno));
},
// setSearchResults: (searchResults) => {
// dispatch(setSearchResults(searchResults));
// },
// setSearchDetails: (searchDetails) => {
// dispatch(setSearchDetails(searchDetails));
// },
setLoggedInUserId: (loggedInUser) => {
dispatch(setLoggedInUserId(loggedInUser));
}
+1 -3
View File
@@ -111,9 +111,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
if (thisSession) {
console.log(" has sesssion.......");
[loggedInUser] = await Promise.all([
await getPortalLogin(thisSession.user.email)
]);
loggedInUser = await getPortalLogin(thisSession.user.email);
loggedInUser = loggedInUser.value[0].contactid;
+9 -3
View File
@@ -141,7 +141,10 @@ const RenderMultiline = ({
className={className}
{...input}
maxLength={
custom.hasOwnProperty("maxFieldLength")
Object.prototype.hasOwnProperty.call(
custom,
"maxFieldLength"
)
? custom.maxFieldLength
? custom.maxFieldLength
: 800
@@ -190,14 +193,17 @@ const RenderTextfield = ({
name={id || name}
id={id || name}
maxLength={
custom.hasOwnProperty("maxFieldLength")
Object.prototype.hasOwnProperty.call(
custom,
"maxFieldLength"
)
? custom.maxFieldLength
? custom.maxFieldLength
: 100
: 200
}
pattern={
custom.hasOwnProperty("pattern")
Object.prototype.hasOwnProperty.call(custom, "pattern")
? custom.pattern
: undefined
}
+1 -3
View File
@@ -142,9 +142,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
if (thisSession) {
console.log(" has sesssion.......");
[loggedInUser] = await Promise.all([
await getPortalLogin(thisSession.user.email)
]);
loggedInUser = await getPortalLogin(thisSession.user.email);
loggedInUser = loggedInUser.value[0].contactid;
+8 -10
View File
@@ -44,7 +44,6 @@ const Home = (props) => {
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
return (
@@ -142,14 +141,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
getIP(req);
console.log("query-", query);
const { cookies } = req;
res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=59"
);
let loggedInUser = cookies.pinsUser;
let loggedInUser = req.cookies.pinsUser;
let thisSession = await getSession(ctx);
@@ -163,8 +160,8 @@ export const getServerSideProps = wrapper.getServerSideProps(
};
} else {
let [accountDetails, watchedCases] = await Promise.all([
await getPersonalAccount(loggedInUser),
await getWatchedCases(loggedInUser)
getPersonalAccount(loggedInUser),
getWatchedCases(loggedInUser)
]);
// searchResultsObj =
@@ -178,9 +175,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
const showMapCheck = process.env.SHOWMAPS || false;
const [watchedCasesDetails] = await Promise.all([
await getDetails(watchedCases, "myWatchedCases")
]);
const watchedCasesDetails = await getDetails(
watchedCases,
"myWatchedCases"
);
const dnsCoords = await getDNSCoords();
// store.dispatch(setSearchResults(searchResultsObj));
// store.dispatch(setSearchDetails(searchDetailsObj));
@@ -201,7 +199,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
const getDetails = (resultsObj, detailsType) => {
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
const detailsObj = resultsObj.map((searchDetail) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"
+51 -4
View File
@@ -6,6 +6,7 @@ import { connect } from "react-redux";
import pLimit from "p-limit";
import { getIP } from "../../actions/core/logger";
import { consoleLogger } from "../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
@@ -184,15 +185,49 @@ export const getServerSideProps = wrapper.getServerSideProps(
const thisSession = await getSession(ctx);
if (!thisSession) {
consoleLogger({
name: "MyPortalIndexAuthGuard",
reasonCode: "NO_SESSION",
message:
"myportal index loader missing session; redirecting to signin"
});
return {
redirect: { destination: "/auth/signin", permanent: false }
};
}
const loggedInUserResponse = await getPortalLogin(
thisSession.user.email
);
const contacts = loggedInUserResponse?.value || [];
if (!thisSession?.user?.email || !thisSession?.user?.id) {
consoleLogger({
name: "MyPortalIndexAuthGuard",
reasonCode: "NO_SESSION_USER",
message:
"myportal index loader missing session user identity; redirecting to signin",
hasSessionUserEmail: !!thisSession?.user?.email,
hasSessionUserId: !!thisSession?.user?.id
});
return {
redirect: { destination: "/auth/signin", permanent: false }
};
}
let contacts = [];
try {
const loggedInUserResponse = await getPortalLogin(
thisSession.user.email
);
contacts = loggedInUserResponse?.value || [];
} catch (error) {
consoleLogger({
name: "MyPortalIndexAuthGuard",
reasonCode: "UPSTREAM_FAILURE",
message:
"myportal index loader portal login lookup failed; redirecting to signin",
error: error?.message
});
return {
redirect: { destination: "/auth/signin", permanent: false }
};
}
if (contacts.length > 1) {
return {
@@ -208,6 +243,18 @@ export const getServerSideProps = wrapper.getServerSideProps(
const loggedInUser = contacts[0]?.contactid;
if (!loggedInUser) {
consoleLogger({
name: "MyPortalIndexAuthGuard",
reasonCode: "CONTACT_LOOKUP_FAILED",
message:
"myportal index loader missing CRM contact id; redirecting to signin"
});
return {
redirect: { destination: "/auth/signin", permanent: false }
};
}
await createContainerProxy(thisSession.user.id);
const accountDetails = await getPersonalAccount(loggedInUser);
+5 -9
View File
@@ -77,14 +77,12 @@ const Home = (props) => {
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
const { query, req } = ctx;
getIP(req);
console.log("query-", query);
const { cookies } = req;
let loggedInUserCookie = cookies.pinsUser;
let thisSession = await getSession(ctx);
const showReps = process.env.SHOWREPRESENTATIONS || false;
@@ -100,9 +98,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
}
};
} else {
let [loggedInUser] = await Promise.all([
await getPortalLogin(thisSession.user.email)
]);
let loggedInUser = await getPortalLogin(thisSession.user.email);
//console.log("sssss", searchResultsObj);
@@ -113,8 +109,8 @@ export const getServerSideProps = wrapper.getServerSideProps(
//console.log("sssss", loggedInUser);
const [accountDetails, watchedCasesDetails] = await Promise.all([
await getPersonalAccount(loggedInUser),
await getDetails(watchedCases, "myWatchedCases")
getPersonalAccount(loggedInUser),
getDetails(watchedCases, "myWatchedCases")
]);
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setSearch(query.q));
@@ -136,7 +132,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
const getDetails = (resultsObj, detailsType) => {
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
const detailsObj = resultsObj.map((searchDetail) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"