Skip to content

Commit

Permalink
fix: Add url validation to team and user avatar fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Aug 30, 2022
1 parent 264f19d commit b8115ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions server/models/Team.ts
Expand Up @@ -16,6 +16,8 @@ import {
Is,
DataType,
IsUUID,
IsUrl,
AllowNull,
} from "sequelize-typescript";
import { getBaseDomain, RESERVED_SUBDOMAINS } from "@shared/utils/domains";
import env from "@server/env";
Expand Down Expand Up @@ -82,6 +84,8 @@ class Team extends ParanoidModel {
@Column(DataType.UUID)
defaultCollectionId: string | null;

@AllowNull
@IsUrl
@Length({ max: 255, msg: "avatarUrl must be 255 characters or less" })
@Column
avatarUrl: string | null;
Expand Down
4 changes: 4 additions & 0 deletions server/models/User.ts
Expand Up @@ -18,6 +18,8 @@ import {
HasMany,
Scopes,
IsDate,
IsUrl,
AllowNull,
} from "sequelize-typescript";
import { languages } from "@shared/i18n";
import { stringToColor } from "@shared/utils/color";
Expand Down Expand Up @@ -154,6 +156,8 @@ class User extends ParanoidModel {
@Column
language: string;

@AllowNull
@IsUrl
@Length({ max: 1000, msg: "avatarUrl must be less than 1000 characters" })
@Column(DataType.STRING)
get avatarUrl() {
Expand Down
5 changes: 3 additions & 2 deletions server/routes/api/attachments.ts
Expand Up @@ -51,10 +51,11 @@ router.post("attachments.create", auth(), async (ctx) => {
const acl =
isPublic === undefined ? AWS_S3_ACL : isPublic ? "public-read" : "private";
const bucket = acl === "public-read" ? "public" : "uploads";
const key = `${bucket}/${user.id}/${s3Key}/${name}`;
const keyPrefix = `${bucket}/${user.id}/${s3Key}`;
const key = `${keyPrefix}/${name}`;
const presignedPost = await getPresignedPost(key, acl, contentType);
const endpoint = publicS3Endpoint();
const url = `${endpoint}/${key}`;
const url = `${endpoint}/${keyPrefix}/${encodeURIComponent(name)}`;

if (documentId !== undefined) {
assertUuid(documentId, "documentId must be a uuid");
Expand Down

0 comments on commit b8115ae

Please sign in to comment.