Skip to content

Commit 1c3b2f3

Browse files
committed
Updates for SSRF
1 parent 50743cc commit 1c3b2f3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/components/Form.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ const Form = ({ formId, petForm, forNewPet = true }) => {
2222

2323
/* The PUT method edits an existing entry in the mongodb database. */
2424
const putData = async (form) => {
25-
const { id } = router.query
25+
const id = parseInt(router.query.id, 10);
2626

27+
if(!id || isNaN(id) || id < 1) {
28+
setMessage('Pet ID is not a number');
29+
return;
30+
}
2731
try {
2832
const res = await fetch(`/api/pets/${id}`, {
2933
method: 'PUT',

src/pages/[id]/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ const PetPage = ({ pet }) => {
99
const router = useRouter()
1010
const [message, setMessage] = useState('')
1111
const handleDelete = async () => {
12-
const petID = router.query.id
12+
const petID = parseInt(router.query.id, 10);
13+
14+
if(!petID || isNaN(petID) || petID < 1) {
15+
setMessage('Pet ID is not a number');
16+
return;
17+
}
1318

1419
try {
1520
await fetch(`/api/pets/${petID}`, {

0 commit comments

Comments
 (0)