@opengeni/core 0.14.4 → 0.15.1

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.
@@ -1,4 +1,4 @@
1
- import type { Settings } from "@opengeni/config";
1
+ import { type Settings } from "@opengeni/config";
2
2
  import { type AccountGrant, type AccessContext, type AccessGrant, type Permission } from "@opengeni/contracts";
3
3
  import { type Database } from "@opengeni/db";
4
4
  import type { Context } from "hono";
package/dist/index.js CHANGED
@@ -757,6 +757,7 @@ async function provisionSandbox(services, ctx, input) {
757
757
  }
758
758
 
759
759
  // src/access/index.ts
760
+ import { resolveFirstPartyDelegationSecret } from "@opengeni/config";
760
761
  import {
761
762
  verifyDelegatedAccessToken
762
763
  } from "@opengeni/contracts";
@@ -837,7 +838,9 @@ function requirePermission(grant, permission) {
837
838
  message: "missing permission: variable-sets:manage (deprecated alias: environments:manage)"
838
839
  });
839
840
  }
840
- throw new HTTPException2(403, { message: `missing permission: ${permission}` });
841
+ throw new HTTPException2(403, {
842
+ message: `missing permission: ${permission}`
843
+ });
841
844
  }
842
845
  }
843
846
  function hasPermission(permissions, permission) {
@@ -899,7 +902,9 @@ async function resolveAccessContext(c, deps) {
899
902
  }
900
903
  }
901
904
  if (deps.managedAuth) {
902
- const session = await deps.managedAuth.api.getSession({ headers: c.req.raw.headers });
905
+ const session = await deps.managedAuth.api.getSession({
906
+ headers: c.req.raw.headers
907
+ });
903
908
  if (session?.user) {
904
909
  return await ensureManagedAccessForUser(deps.db, {
905
910
  userId: session.user.id,
@@ -950,10 +955,11 @@ async function apiKeyAccessContext(c, deps, mode) {
950
955
  };
951
956
  }
952
957
  async function delegatedAccessContext(c, deps, mode, token = bearerToken(c)) {
953
- if (!token || !deps.settings.delegationSecret) {
958
+ const delegationSecret = resolveFirstPartyDelegationSecret(deps.settings);
959
+ if (!token || !delegationSecret) {
954
960
  return null;
955
961
  }
956
- const payload = await verifyDelegatedAccessToken(deps.settings.delegationSecret, token);
962
+ const payload = await verifyDelegatedAccessToken(delegationSecret, token);
957
963
  if (!payload) {
958
964
  return null;
959
965
  }
@@ -1019,7 +1025,8 @@ import {
1019
1025
  import {
1020
1026
  getSession,
1021
1027
  getSessionRootId,
1022
- getSessionTurnForAttempt
1028
+ getSessionTurnForAttempt,
1029
+ getSlackInteractionSessionAccessForSession
1023
1030
  } from "@opengeni/db";
1024
1031
  var SESSION_AUTHORIZATION_DEFAULT_REAUTHORIZE_MS = 15e3;
1025
1032
  var SessionAuthorizationDeniedError = class extends Error {
@@ -1039,11 +1046,19 @@ var SessionAuthorizationUnavailableError = class extends Error {
1039
1046
  };
1040
1047
  async function requireSessionAuthorization(deps, grant, input) {
1041
1048
  const port = deps.sessionAuthorization;
1049
+ const slackAccess = await getSlackInteractionSessionAccessForSession(deps.db, {
1050
+ accountId: grant.accountId,
1051
+ workspaceId: grant.workspaceId,
1052
+ sessionId: input.sessionId
1053
+ });
1054
+ if (!port && slackAccess?.visibility !== "private") return null;
1055
+ const actor = await resolveSessionAuthorizationActor(deps.db, grant);
1056
+ const target = slackAccess ? { sessionId: input.sessionId, rootSessionId: slackAccess.rootSessionId } : await resolveSessionAuthorizationTarget(deps.db, grant, input.sessionId);
1057
+ if (slackAccess?.visibility === "private") {
1058
+ const allowed = actor.kind === "subject" ? actor.subjectId === slackAccess.owningSubjectId : actor.callerRootSessionId === target.rootSessionId;
1059
+ if (!allowed) throw new SessionAuthorizationDeniedError("forbidden");
1060
+ }
1042
1061
  if (!port) return null;
1043
- const [actor, target] = await Promise.all([
1044
- resolveSessionAuthorizationActor(deps.db, grant),
1045
- resolveSessionAuthorizationTarget(deps.db, grant, input.sessionId)
1046
- ]);
1047
1062
  let rawDecision;
1048
1063
  try {
1049
1064
  rawDecision = await port.authorizeSession({