strapi-security-suite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ import { useRef, useEffect } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { User } from "@strapi/icons";
4
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
5
+ const v = glob[path];
6
+ if (v) {
7
+ return typeof v === "function" ? v() : Promise.resolve(v);
8
+ }
9
+ return new Promise((_, reject) => {
10
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
11
+ reject.bind(
12
+ null,
13
+ new Error(
14
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
15
+ )
16
+ )
17
+ );
18
+ });
19
+ };
20
+ const PLUGIN_ID = "strapi-security-suite";
21
+ const Initializer = ({ setPlugin }) => {
22
+ const ref = useRef(setPlugin);
23
+ useEffect(() => {
24
+ ref.current(PLUGIN_ID);
25
+ }, []);
26
+ return null;
27
+ };
28
+ const PluginIcon = () => /* @__PURE__ */ jsx(User, {});
29
+ const autologout = () => {
30
+ console.warn("💥 Intercepted module import failure! Executing backup plan.");
31
+ localStorage.setItem("isLoggedIn", "false");
32
+ sessionStorage.clear();
33
+ document.cookie = "koa.sess=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;";
34
+ document.cookie = "koa.sess.sig=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;";
35
+ document.cookie = "jwtToken=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;";
36
+ setTimeout(() => {
37
+ window.location.href = "/admin/auth/login?t=" + Date.now();
38
+ }, 50);
39
+ };
40
+ const index = {
41
+ register(app) {
42
+ app.addMenuLink({
43
+ to: `plugins/${PLUGIN_ID}`,
44
+ icon: PluginIcon,
45
+ intlLabel: {
46
+ id: `${PLUGIN_ID}.plugin.name`,
47
+ defaultMessage: PLUGIN_ID
48
+ },
49
+ Component: async () => {
50
+ const { App } = await import("../_chunks/App-h9NYFBrR.mjs");
51
+ return App;
52
+ },
53
+ permissions: [
54
+ {
55
+ action: "plugin::strapi-security-suite.access",
56
+ subject: null
57
+ }
58
+ ]
59
+ });
60
+ app.registerPlugin({
61
+ id: PLUGIN_ID,
62
+ initializer: Initializer,
63
+ isReady: false,
64
+ name: PLUGIN_ID
65
+ });
66
+ const originalSetItem = Storage.prototype.setItem;
67
+ Storage.prototype.setItem = function(key, value) {
68
+ console.log(`🕵️ Intercepted localStorage.setItem:`, key, value);
69
+ return originalSetItem.apply(this, arguments);
70
+ };
71
+ if (!window.__fetchPatchedForSession) {
72
+ window.addEventListener("unhandledrejection", function(event) {
73
+ if (event.reason?.message?.includes("Importing a module script failed")) {
74
+ autologout();
75
+ }
76
+ });
77
+ window.addEventListener("error", function(event) {
78
+ const message = event.message || "";
79
+ if (message.includes("Importing a module script failed")) {
80
+ autologout();
81
+ }
82
+ });
83
+ const originalFetch = window.fetch;
84
+ window.fetch = async (...args) => {
85
+ try {
86
+ const response = await originalFetch(...args);
87
+ if ([400, 440].includes(response.status)) {
88
+ if (window.stop) window.stop();
89
+ if (document.execCommand) document.execCommand("Stop");
90
+ window.location.reload();
91
+ return;
92
+ }
93
+ return response;
94
+ } catch (err) {
95
+ console.log(err);
96
+ if (err?.message?.includes("MIME")) {
97
+ window.location.reload();
98
+ return;
99
+ }
100
+ }
101
+ };
102
+ window.__fetchPatchedForSession = true;
103
+ }
104
+ },
105
+ async registerTrads({ locales }) {
106
+ return Promise.all(
107
+ locales.map(async (locale) => {
108
+ try {
109
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("../_chunks/en-Byx4XI2L.mjs") }), `./translations/${locale}.json`, 3);
110
+ return { data, locale };
111
+ } catch {
112
+ return { data: {}, locale };
113
+ }
114
+ })
115
+ );
116
+ }
117
+ };
118
+ export {
119
+ index as default
120
+ };