Notes
![]() ![]() Notes - notes.io |
This page has four areas: Information about the challenge with a radiogroup of options to select as answer, a tree view “File Explorer” containing the project files, a “Code blocks” section with a list of code blocks relevant to the challenge, and a code viewer section. The code viewer section has tabs displaying opened files, with the currently opened file presented in a table. This table has three columns: Code block indicator (only present on the first line of a code block), line number, and the code itself. Each line of code within a code block is prefixed with ‘CBX’, where X is a number used to distinguish between code blocks. Opening category information, hints or submit buttons will open a modal dialog.
Skip to Code Editor
Identify the vulnerability
Fix the vulnerability
Identify the vulnerability
Identify the type of vulnerability present in the code. Code blocks that are vulnerable are marked with warning icons (). Additional code blocks that may give context may be marked with lightbulb icons ().
Select Vulnerability Category
Access Control
Missing Object Level Access Control
Authentication
Insecure Password Change Function
Memory Corruption
Null Dereference
Mass Assignment
Mass Assignment
Actions
Attempts left: 1
View shortcuts keyboard hotkey:?
File Explorer
Highlighted files only: 85 files hidden
Services3 code blocks
Domain3 code blocks
ReviewAttachmentService.cs3 code blocks
3
Code blocks
ReviewAttachmentService.cs:48-55
ReviewAttachmentService.cs:61-82
ReviewAttachmentService.cs:102-121
using ProductsCatalog.Extensions;
using ProductsCatalog.Models.Domain;
using ProductsCatalog.Models.ReviewAttachment;
using ProductsCatalog.Services.Database;
using ProductsCatalog.Services.Exceptions;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace ProductsCatalog.Services.Domain
{
public class ReviewAttachmentService
{
private static readonly string ReviewAttachmentsDirectory =
AppSettings.Get("ReviewAttachmentsDirectory");
private readonly UploadsManager uploadsManager = new UploadsManager(ReviewAttachmentsDirectory);
public FileStream GetFileStream(ReviewAttachment attachment) =>
this.uploadsManager.GetFileAsStream(
attachment.RelativePath);
public Task<ReviewAttachment[]> GetReviewAttachments(int reviewId) =>
CatalogDatabase.Query<ReviewAttachment>(
"SELECT a.* " +
"FROM V_ReviewAttachment a " +
"WHERE a.ReviewId=@ReviewId",
new { reviewId });
public Task<ReviewAttachment> Get(int attachId) =>
CatalogDatabase.QueryFirstOrDefault<ReviewAttachment>(
"SELECT * " +
"FROM V_ReviewAttachment " +
"WHERE Id=@AttachId",
new { attachId });
public Task<string> GetRelativePath(int attachId) =>
CatalogDatabase.ExecuteScalar<string>(
"SELECT RelativePath " +
"FROM ReviewAttachment " +
"WHERE Id=@AttachId",
new { attachId });
public async Task<bool> Delete(int attachId)
{
var path = await GetRelativePath(attachId);
var result = await CatalogDatabase.Execute(
"DELETE FROM ReviewAttachment " +
"WHERE Id=@AttachId",
new {attachId});
if (result)
this.uploadsManager.DeleteFile(path);
return result;
}
public async Task<int[]> AddAttachments(
ReviewAttachmentInputInsertModel model)
{
ValidateFiles(model.Attachments);
var models = await SaveFiles(model);
var result = new int[models.Length];
using (var conn = await CatalogDatabase.OpenConnection())
using (var tran = conn.BeginTransaction())
{
for (int i = 0; i < models.Length; i++)
{
var id = await CatalogDatabase.ExecuteScalar<int>(
"INSERT INTO ReviewAttachment " +
"(ReviewId, RelativePath, Filename, ContentType, UploadedBy, UploadedAt) " +
"OUTPUT INSERTED.Id " +
"VALUES (@ReviewId, @RelativePath, @Filename, @ContentType, @UploadedBy, @UploadedAt)",
models[i]);
result[i] = id;
}
tran.Commit();
}
return result;
}
public Task<ReviewAttachment[]> SaveFiles(ReviewAttachmentInputInsertModel model) =>
Task.WhenAll(model
.Attachments
.FilesCollection()
.Select(async x => new ReviewAttachment
{
ReviewId = model.ReviewId,
RelativePath = await this.uploadsManager.SaveFile(x.InputStream),
Filename = x.FileName,
ContentType = x.ContentType,
UploadedBy = UserManager.UserId,
UploadedAt = DateTime.Now
}));
public async Task<int> AddAttachmentFromUrl(
ReviewAttachmentFromUrlInputInsertModel model)
{
var file = await ImageDownloader.Download(model.Url);
if (this.uploadsManager.IsFileExists(file.Stream))
throw new GeneralApiException(
$"File {file.FileName} already exists");
var attachModel = new ReviewAttachment
{
ReviewId = model.ReviewId,
RelativePath = await this.uploadsManager.SaveFile(file.Stream),
Filename = file.FileName,
ContentType = file.ContentType,
UploadedBy = UserManager.UserId,
UploadedAt = DateTime.Now
};
return await CatalogDatabase.ExecuteScalar<int>(
"INSERT INTO ReviewAttachment " +
"(ReviewId, RelativePath, Filename, ContentType, UploadedBy, UploadedAt) " +
"OUTPUT INSERTED.Id " +
"VALUES (@ReviewId, @RelativePath, @Filename, @ContentType, @UploadedBy, @UploadedAt)",
attachModel);
}
public void ValidateFiles(HttpFileCollection files)
{
foreach (var file in files.FilesCollection())
{
if (file.ContentLength > 10 * 1024 * 1024)
throw new GeneralApiException("Maximum file size is 10Mb");
if (!ImageDownloader.ImageHeaders.ContainsKey(
file.ContentType))
throw new GeneralApiException(
"Unacceptable content-type");
if (!ImageDownloader.IsValidHeader(
file.ContentType, file.InputStream))
throw new GeneralApiException(
"Invalid file header");
if (this.uploadsManager.IsFileExists(file.InputStream))
throw new GeneralApiException(
$"File {file.FileName} already exists");
}
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team