Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add input validation for gitURL and slug in POST /project endpoint #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions api-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,24 @@ app.use(express.json())

app.post('/project', async (req, res) => {
const { gitURL, slug } = req.body
const projectSlug = slug ? slug : generateSlug()

// Regular expression to validate GitHub URL format
const githubUrlRegex = /^https?:\/\/github\.com\/[^\/]+\/[^\/]+$/;

// Regular expression to validate slug format (no spaces, alphanumeric characters)
const slugRegex = /^[a-zA-Z0-9-]+$/;

// Validate gitURL format
if (!urlRegex.test(gitURL)) {
return res.status(400).json({ status:"error", error: 'Please Enter Valid Git URL' });
}

// Validate slug format
if (slug && (!slugRegex.test(slug) || slug.includes(' '))) {
return res.status(400).json({ status:"error", error: 'Please Enter Valid Slug Format' });
}

const projectSlug = slug;
codeterrayt marked this conversation as resolved.
Show resolved Hide resolved

// Spin the container
const command = new RunTaskCommand({
Expand Down Expand Up @@ -82,4 +99,4 @@ async function initRedisSubscribe() {

initRedisSubscribe()

app.listen(PORT, () => console.log(`API Server Running..${PORT}`))
app.listen(PORT, () => console.log(`API Server Running..${PORT}`))