Skip to content

Commit

Permalink
feat: limit expiry to 1 month & minor ui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala committed Jun 7, 2024
1 parent 525530b commit aa69f5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ import { Knex } from "knex";
import { TableName } from "../schemas";

export async function up(knex: Knex): Promise<void> {
const hasOrgIdColumn = await knex.schema.hasColumn(TableName.SecretSharing, "orgId");
const hasUserIdColumn = await knex.schema.hasColumn(TableName.SecretSharing, "userId");

if (await knex.schema.hasTable(TableName.SecretSharing)) {
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
t.uuid("orgId").nullable().alter();
t.uuid("userId").nullable().alter();
if (hasOrgIdColumn) t.uuid("orgId").nullable().alter();
if (hasUserIdColumn) t.uuid("userId").nullable().alter();
});
}
}

export async function down(knex: Knex): Promise<void> {
const hasOrgIdColumn = await knex.schema.hasColumn(TableName.SecretSharing, "orgId");
const hasUserIdColumn = await knex.schema.hasColumn(TableName.SecretSharing, "userId");

if (await knex.schema.hasTable(TableName.SecretSharing)) {
await knex.schema.alterTable(TableName.SecretSharing, (t) => {
t.uuid("orgId").notNullable().alter();
t.uuid("userId").notNullable().alter();
if (hasOrgIdColumn) t.uuid("orgId").notNullable().alter();
if (hasUserIdColumn) t.uuid("userId").notNullable().alter();
});
}
}
8 changes: 8 additions & 0 deletions backend/src/services/secret-sharing/secret-sharing-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export const secretSharingServiceFactory = ({
throw new BadRequestError({ message: "Expiration date cannot be in the past" });
}

// Limit Expiry Time to 1 month
const expiryTime = new Date(expiresAt).getTime();
const currentTime = new Date().getTime();
const thirtyDays = 30 * 24 * 60 * 60 * 1000;
if (expiryTime - currentTime > thirtyDays) {
throw new BadRequestError({ message: "Expiration date cannot be more than 30 days currently." });
}

const newSharedSecret = await secretSharingDAL.create({
encryptedValue,
iv,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/api/secretSharing/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const useGetSharedSecrets = () => {
export const useGetActiveSharedSecretByIdAndHashedHex = (id: string, hashedHex: string) => {
return useQuery<TViewSharedSecretResponse, [string]>({
queryFn: async () => {
if(!id || !hashedHex) return Promise.resolve({ encryptedValue: "", iv: "", tag: "" });
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
`/api/v1/secret-sharing/public/${id}?hashedHex=${hashedHex}`
);
Expand Down

0 comments on commit aa69f5b

Please sign in to comment.