Skip to content

Commit c12e545

Browse files
committed
#101700 change csrf token access
1 parent 249b8b0 commit c12e545

File tree

12 files changed

+27
-65
lines changed

12 files changed

+27
-65
lines changed

netbox/project-static/dist/config.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/config.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/lldp.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/lldp.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/netbox.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/status.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/dist/status.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netbox/project-static/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"bootstrap": "~5.0.2",
2828
"clipboard": "^2.0.8",
2929
"color2k": "^1.2.4",
30-
"cookie": "^0.4.1",
3130
"dayjs": "^1.10.4",
3231
"flatpickr": "4.6.3",
3332
"htmx.org": "^1.6.1",

netbox/project-static/src/util.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import Cookie from 'cookie';
2-
31
type Method = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
42
type ReqData = URLSearchParams | Dict | undefined | unknown;
53
type SelectedOption = { name: string; options: string[] };
64

5+
declare global {
6+
interface Window { CSRF_TOKEN: any; }
7+
}
8+
79
/**
810
* Infer valid HTMLElement props based on element name.
911
*/
@@ -93,23 +95,12 @@ export function isElement(obj: Element | null | undefined): obj is Element {
9395
return typeof obj !== null && typeof obj !== 'undefined';
9496
}
9597

96-
/**
97-
* Retrieve the CSRF token from cookie storage.
98-
*/
99-
function getCsrfToken(): string {
100-
const { csrftoken: csrfToken } = Cookie.parse(document.cookie);
101-
if (typeof csrfToken === 'undefined') {
102-
throw new Error('Invalid or missing CSRF token');
103-
}
104-
return csrfToken;
105-
}
106-
10798
export async function apiRequest<R extends Dict, D extends ReqData = undefined>(
10899
url: string,
109100
method: Method,
110101
data?: D,
111102
): Promise<APIResponse<R>> {
112-
const token = getCsrfToken();
103+
const token = window.CSRF_TOKEN;
113104
const headers = new Headers({ 'X-CSRFToken': token });
114105

115106
let body;

0 commit comments

Comments
 (0)