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

Anonymization sanitization feature #16

Open
wants to merge 3 commits into
base: f24
Choose a base branch
from
Open
Changes from all commits
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
19 changes: 18 additions & 1 deletion src/controllers/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
Topics.create = async (req, res) => {
const id = await lockPosting(req, '[[error:already-posting]]');
try {
console.log("Anonymous flag received in create:", req.body.anonymous);

Check failure on line 20 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
const payload = await api.topics.create(req, req.body);
console.log("Post object before save:", payload);

Check failure on line 22 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
if (payload.queued) {
helpers.formatApiResponse(202, res, payload);
} else {
Expand All @@ -31,11 +33,26 @@
Topics.reply = async (req, res) => {
const id = await lockPosting(req, '[[error:already-posting]]');
try {
console.log("Anonymous flag received in reply:", isAnonymous);

Check failure on line 36 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote

Check failure on line 36 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

'isAnonymous' was used before it was defined
const isAnonymous = req.body.anon;
let replyData = { ...req.body, tid: req.params.tid };

Check failure on line 38 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 tabs but found 8 spaces

Check failure on line 38 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

'replyData' is never reassigned. Use 'const' instead

// Sanitize content to avoid XSS attacks
replyData.content = validator.escape(replyData.content);

Check failure on line 41 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

'validator' is not defined

if (isAnonymous) {

Check failure on line 43 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 tabs but found 8 spaces
console.log("Post is anonymous. Modifying the username and userslug.");

Check failure on line 44 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 3 tabs but found 12 spaces

Check failure on line 44 in src/controllers/write/topics.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
replyData.username = 'Anonymous User';
replyData.userslug = null;
} else {
console.log("Post is not anonymous.");
}
console.log("Final reply data being sent:", replyData);
const payload = await api.topics.reply(req, { ...req.body, tid: req.params.tid });
helpers.formatApiResponse(200, res, payload);
} finally {
await db.deleteObjectField('locks', id);
}
}gi
};

async function lockPosting(req, error) {
Expand Down