Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit ae3ff91

Browse files
author
Greg Rickaby
authored
Merge pull request #140 from WebDevStudios/feature/60-comment-spam-protection
Feature/60 comment spam protection
2 parents 4fba5ea + 0b43cf6 commit ae3ff91

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

api/frontend/wp/comments/mutationAddComment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const mutationAddComment = gql`
1818
postId: $postId,
1919
content: $content
2020
) @rest(type: "Comments", path: "${wpDataEndpoints.postComment}?{args}") {
21+
success
2122
comment {
2223
${commentsFields}
2324
}

api/wordpress/_global/postCommentToPost.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default async function postCommentToPost(
3636
// Set up return object.
3737
const response = {
3838
apolloClient,
39+
success: false,
3940
comment: null
4041
}
4142

@@ -61,6 +62,7 @@ export default async function postCommentToPost(
6162
return null
6263
}
6364

65+
response.success = data.createComment.success
6466
response.comment = data.createComment.comment
6567
})
6668
.catch((error) => {

api/wordpress/comments/mutationCommentToPost.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const mutationCommentToPost = gql`
1919
content: $content
2020
}
2121
) {
22+
success
2223
comment {
2324
${commentsFields}
2425
}

pages/api/wp/postComment.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ export default async function postComment(req, res) {
1212
// Retrieve props from request query params.
1313
const {author, authorEmail, authorUrl, postId, content} = req.query
1414

15+
// Basic check to see if the referer matches the host.
16+
// This is trivially easy to bypass, but it's a first step.
17+
if (
18+
!req.headers.referer ||
19+
!req.headers.referer.includes(req.headers.host)
20+
) {
21+
throw new Error('Unauthorized access')
22+
}
23+
1524
const commentResponse = await postCommentToPost(
1625
author,
1726
authorEmail,

0 commit comments

Comments
 (0)