Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jan 5, 2025
1 parent 6c26322 commit a357092
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 20 additions & 6 deletions backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ route.GET('/eventsAfter/{contractID}/{since}/{limit?}', {}, async function (requ
const { contractID, since, limit } = request.params
const ip = request.headers['x-real-ip'] || request.info.remoteAddress
try {
if (contractID.startsWith('_private') || since.startsWith('_private')) {
if (
!contractID ||
!CONTRACT_DATA_REGEX.test(contractID) ||
contractID.startsWith('_private') ||
!/^[0-9]+$/.test(since) ||
(limit && !/^[0-9]+$/.test(limit))
) {
return Boom.notFound()
}

Expand Down Expand Up @@ -271,7 +277,12 @@ route.GET('/latestHEADinfo/{contractID}', {
}, async function (request, h) {
const { contractID } = request.params
try {
if (contractID.startsWith('_private')) return Boom.notFound()
if (
!contractID ||
!CONTRACT_DATA_REGEX.test(contractID) ||
contractID.startsWith('_private')
) return Boom.notFound()

const HEADinfo = await sbp('chelonia/db/latestHEADinfo', contractID)
if (!HEADinfo) {
console.warn(`[backend] latestHEADinfo not found for ${contractID}`)
Expand Down Expand Up @@ -465,7 +476,7 @@ route.GET('/file/{hash}', {
}, async function (request, h) {
const { hash } = request.params

if (hash.startsWith('_private')) {
if (!hash || hash.startsWith('_private')) {
return Boom.notFound()
}

Expand Down Expand Up @@ -509,7 +520,10 @@ route.POST('/deleteFile/{hash}', {
}, async function (request, h) {
const { hash } = request.params
const strategy = request.auth.strategy
if (!hash || hash.startsWith('_private')) return Boom.notFound()
if (!hash || !FILE_MANIFEST_REGEX.test(hash) || hash.startsWith('_private')) {
return Boom.notFound()
}

const owner = await sbp('chelonia/db/get', `_private_owner_${hash}`)
if (!owner) {
return Boom.notFound()
Expand Down Expand Up @@ -605,7 +619,7 @@ route.POST('/kv/{contractID}/{key}', {
}, async function (request, h) {
const { contractID, key } = request.params

if (key.startsWith('_private')) {
if (!CONTRACT_DATA_REGEX.test(contractID) || !key || key.startsWith('_private')) {
return Boom.notFound()
}

Expand Down Expand Up @@ -686,7 +700,7 @@ route.GET('/kv/{contractID}/{key}', {
}, async function (request, h) {
const { contractID, key } = request.params

if (key.startsWith('_private')) {
if (!CONTRACT_DATA_REGEX.test(contractID) || !key || key.startsWith('_private')) {
return Boom.notFound()
}

Expand Down
2 changes: 0 additions & 2 deletions test/avatar-caching.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('avatar file serving', function () {
}
}
})
console.error('@@@@@ 82')
const owner = await createIdentity('avatar-caching-test')
const fd = new FormData()
fd.append(
Expand All @@ -98,7 +97,6 @@ describe('avatar file serving', function () {
{ type: 'application/vnd.shelter.manifest' }
)
)
console.error('@@@@@ 100')
retPath = await fetch(`${apiURL}/file`, {
method: 'POST',
headers: {
Expand Down

0 comments on commit a357092

Please sign in to comment.