You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//log.Printf("[AUDIT] INITIAL Api authentication failed in Create notification api: %s", err)
929
-
930
-
// Allows for execution authorization
931
-
iflen(notification.ExecutionId) ==0 {
932
-
log.Printf("[INFO] User tried to create notification for execution %s with org id %s, but notification org id is %s", notification.ExecutionId, orgId,notification.OrgId)
933
-
resp.WriteHeader(403)
934
-
resp.Write([]byte(`{"success": false}`))
935
-
return
954
+
log.Printf("[AUDIT] INITIAL Api authentication failed in Create notification api: %s", err)
log.Printf("[INFO] User tried to create notification for execution %s without authorization", exec.ExecutionId)
973
-
resp.WriteHeader(403)
974
-
resp.Write([]byte(`{"success": false}`))
975
-
return
976
-
}
991
+
found:=false
992
+
for_, env:=rangeenvironments {
993
+
ifenv.Name==environment&&env.Auth==authKey {
994
+
found=true
995
+
break
996
+
}
997
+
}
977
998
978
-
// Check if exec org id is same
979
-
ifexec.OrgId!=notification.OrgId {
980
-
log.Printf("[WARNING] User tried to create notification for execution %s with org id %s, but notification org id is %s", exec.ExecutionId, exec.OrgId, notification.OrgId)
981
-
}
999
+
if!found {
1000
+
log.Printf("[AUDIT] Invalid authorization header in create notification api for Orborus request")
1001
+
resp.WriteHeader(403)
1002
+
resp.Write([]byte(`{"success": false, "reason": "Invalid authorization config for Environment auth"}`))
// Check if user has access. Parse out authorization header with "Bearer X"
1026
+
authHeader:=request.Header.Get("Authorization")
1027
+
iflen(authHeader) ==0 {
1028
+
log.Printf("[INFO] No authorization header in create notification api")
1029
+
resp.WriteHeader(401)
1030
+
resp.Write([]byte(`{"success": false}`))
1031
+
return
1032
+
}
998
1033
999
-
iflen(orgId) ==0 {
1000
-
log.Printf("[ERROR] No org id found in create notification api from worker(?)")
1001
-
resp.WriteHeader(400)
1002
-
resp.Write([]byte(`{"success": false}`))
1003
-
return
1034
+
authHeaderParts:=strings.Split(authHeader, " ")
1035
+
iflen(authHeaderParts) !=2 {
1036
+
log.Printf("[INFO] Invalid authorization header in create notification api")
1037
+
resp.WriteHeader(401)
1038
+
resp.Write([]byte(`{"success": false}`))
1039
+
return
1040
+
}
1041
+
1042
+
ifauthHeaderParts[0] !="Bearer" {
1043
+
log.Printf("[INFO] Invalid authorization header in create notification api")
1044
+
resp.WriteHeader(401)
1045
+
resp.Write([]byte(`{"success": false}`))
1046
+
return
1047
+
}
1048
+
1049
+
// Check if user has access to execution
1050
+
ifauthHeaderParts[1] !=exec.Authorization {
1051
+
log.Printf("[INFO] User tried to create notification for execution %s without authorization", exec.ExecutionId)
1052
+
resp.WriteHeader(403)
1053
+
resp.Write([]byte(`{"success": false}`))
1054
+
return
1055
+
}
1056
+
1057
+
// Check if exec org id is same
1058
+
ifexec.OrgId!=notification.OrgId {
1059
+
log.Printf("[WARNING] User tried to create notification for execution %s with org id %s, but notification org id is %s", exec.ExecutionId, exec.OrgId, notification.OrgId)
0 commit comments