Skip to content

Commit

Permalink
csrf_token is marked with _
Browse files Browse the repository at this point in the history
CMK-18866

Change-Id: I60bd4f0a674c12c198dfed88aee0bb392971cea7
  • Loading branch information
hrantzsch committed Sep 17, 2024
1 parent e8af2b5 commit 96652d0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmk/gui/htmllib/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def begin_form(
enctype=enctype if method.lower() == "post" else None,
)
if hasattr(session, "session_info"):
self.hidden_field("csrf_token", session.session_info.csrf_token)
self.hidden_field("_csrf_token", session.session_info.csrf_token)

self.hidden_field("filled_in", name, add_var=True)
if add_transid:
Expand Down
4 changes: 2 additions & 2 deletions cmk/gui/utils/csrf_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def check_csrf_token(token: str | None = None) -> None:
if isinstance(session.user, LoggedInNobody):
return

csrf_token = token or request.get_str_input("csrf_token")
csrf_token = token or request.get_str_input("_csrf_token")
if csrf_token is None:
csrf_token = request.get_request().get("csrf_token")
csrf_token = request.get_request().get("_csrf_token")

if csrf_token is None:
log_security_event(
Expand Down
4 changes: 2 additions & 2 deletions cmk/gui/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def makeactionuri(
) -> str:
session_vars: HTTPVariables = [("_transid", transaction_manager.get())]
if session and hasattr(session, "session_info"):
session_vars.append(("csrf_token", session.session_info.csrf_token))
session_vars.append(("_csrf_token", session.session_info.csrf_token))

return makeuri(request, addvars + session_vars, filename=filename, delvars=delvars)

Expand All @@ -254,7 +254,7 @@ def makeactionuri_contextless(
) -> str:
session_vars: HTTPVariables = [("_transid", transaction_manager.get())]
if session and hasattr(session, "session_info"):
session_vars.append(("csrf_token", session.session_info.csrf_token))
session_vars.append(("_csrf_token", session.session_info.csrf_token))

return makeuri_contextless(request, addvars + session_vars, filename=filename)

Expand Down
2 changes: 1 addition & 1 deletion cmk/gui/watolib/hosts_and_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ def folder_preserving_link(add_vars: HTTPVariables) -> str:
def make_action_link(vars_: HTTPVariables) -> str:
session_vars: HTTPVariables = [("_transid", transactions.get())]
if session and hasattr(session, "session_info"):
session_vars.append(("csrf_token", session.session_info.csrf_token))
session_vars.append(("_csrf_token", session.session_info.csrf_token))

return folder_preserving_link(vars_ + session_vars)

Expand Down
6 changes: 3 additions & 3 deletions packages/cmk-frontend/src/js/modules/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ export function call_ajax<HandlerData = any>(
}
if (
typeof args.post_data == "string" &&
!args.post_data.includes("&csrf_token=") &&
!args.post_data.startsWith("csrf_token=")
!args.post_data.includes("&_csrf_token=") &&
!args.post_data.startsWith("_csrf_token=")
) {
args.post_data +=
"&csrf_token=" + encodeURIComponent(global_csrf_token);
"&_csrf_token=" + encodeURIComponent(global_csrf_token);
}

AJAX.send(args.post_data);
Expand Down
2 changes: 1 addition & 1 deletion packages/cmk-frontend/src/js/modules/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export function confirm_link(
document.createElement("input"),
{
type: "hidden",
name: "csrf_token",
name: "_csrf_token",
value: global_csrf_token,
}
);
Expand Down

0 comments on commit 96652d0

Please sign in to comment.