Skip to content

Commit

Permalink
Fix input validation for message length in Chat.tsx and main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jun 16, 2024
1 parent e9d17de commit f532c58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions islands/Chats/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ export default function Home(
class="p-talk-chat-send__file"
onClick={() => {
if (Message) {
if (messages.length > 100) {

if (Message.length > 100) {
alert(
"100文字以内で入力してください",
)
return
}
const data = {
Expand Down
7 changes: 7 additions & 0 deletions routes/api/v1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import pubClient from "../../../util/redisClient.ts"
const env = await load()
const redisURL = env["REDIS_URL"]
const redisch = env["REDIS_CH"]
const maxMessage = Number(env["MAX_MESSAGE_LENGTH"])
const subClient = redis.createClient({
url: redisURL,
})
Expand Down Expand Up @@ -215,6 +216,9 @@ async function sendMessage(
return
}
if (session.roomType === "friend") {
if(message.length > maxMessage){
return
}
const result = await messages.create({
userid: session.uuid,
roomid: roomID,
Expand Down Expand Up @@ -277,6 +281,9 @@ async function sendMessage(
}
const frienduuid = friend.userid
const messageid = crypto.randomUUID()
if(message.length > maxMessage){
return
}
await messages.create({
userid: session.uuid,
roomid: roomID,
Expand Down
4 changes: 4 additions & 0 deletions routes/api/v1/server/talk/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { takosfetch } from "../../../../../util/takosfetch.ts"
import { load } from "$std/dotenv/mod.ts"
const env = await load()
const redisch = env["REDIS_CH"]
const maxMessage = Number(env["MAX_MESSAGE_LENGTH"])
export const handler = {
async POST(req: Request, ctx: any) {
const data = await req.json()
Expand Down Expand Up @@ -62,6 +63,9 @@ export const handler = {
status: 400,
})
}
if(message.length > maxMessage){
return
}
const result = await messages.create({
userid: uuid,
roomid,
Expand Down

0 comments on commit f532c58

Please sign in to comment.