mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-22 07:32:31 +02:00
fix: remove public access from do space and generate signed url wherever PDF files are accessed
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import getPresignedUrl from './getSignedUrl.js';
|
||||
|
||||
async function DocumentAfterFind(request) {
|
||||
if (request.objects.length === 1) {
|
||||
if (request.objects) {
|
||||
const obj = request.objects[0];
|
||||
const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl');
|
||||
const Url = obj?.get('URL') && obj?.get('URL');
|
||||
const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl');
|
||||
if (SignedUrl) {
|
||||
obj.set('SignedUrl', getPresignedUrl(SignedUrl));
|
||||
}
|
||||
if (Url) {
|
||||
obj.set('URL', getPresignedUrl(Url));
|
||||
}
|
||||
if (certificateUrl) {
|
||||
obj.set('CertificateUrl', getPresignedUrl(certificateUrl));
|
||||
}
|
||||
|
||||
return [obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
export default DocumentAfterFind;
|
||||
@@ -0,0 +1,22 @@
|
||||
import getPresignedUrl from './getSignedUrl.js';
|
||||
|
||||
async function SignatureAfterFind(request) {
|
||||
if (request.objects.length === 1) {
|
||||
if (request.objects) {
|
||||
const obj = request.objects[0];
|
||||
const ImageURL = obj?.get('ImageURL') && obj?.get('ImageURL');
|
||||
const Initials = obj?.get('Initials') && obj?.get('Initials');
|
||||
|
||||
if (ImageURL) {
|
||||
obj.set('ImageURL', getPresignedUrl(ImageURL));
|
||||
}
|
||||
|
||||
if (Initials) {
|
||||
obj.set('Initials', getPresignedUrl(Initials));
|
||||
}
|
||||
|
||||
return [obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
export default SignatureAfterFind;
|
||||
@@ -0,0 +1,24 @@
|
||||
import getPresignedUrl from './getSignedUrl.js';
|
||||
|
||||
async function TemplateAfterFind(request) {
|
||||
if (request.objects.length === 1) {
|
||||
if (request.objects) {
|
||||
const obj = request.objects[0];
|
||||
const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl');
|
||||
const Url = obj?.get('URL') && obj?.get('URL');
|
||||
const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl');
|
||||
if (SignedUrl) {
|
||||
obj.set('SignedUrl', getPresignedUrl(SignedUrl));
|
||||
}
|
||||
if (Url) {
|
||||
obj.set('URL', getPresignedUrl(Url));
|
||||
}
|
||||
if (certificateUrl) {
|
||||
obj.set('CertificateUrl', getPresignedUrl(certificateUrl));
|
||||
}
|
||||
|
||||
return [obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
export default TemplateAfterFind;
|
||||
@@ -0,0 +1,17 @@
|
||||
import getPresignedUrl from './getSignedUrl.js';
|
||||
|
||||
async function UserAfterFind(request) {
|
||||
if (request.objects.length === 1) {
|
||||
if (request.objects) {
|
||||
const obj = request.objects[0];
|
||||
const ProfilePic = obj?.get('ProfilePic') && obj?.get('ProfilePic');
|
||||
|
||||
if (ProfilePic) {
|
||||
obj.set('ProfilePic', getPresignedUrl(ProfilePic));
|
||||
}
|
||||
|
||||
return [obj];
|
||||
}
|
||||
}
|
||||
}
|
||||
export default UserAfterFind;
|
||||
@@ -21,7 +21,7 @@ export default async function getDocument(request) {
|
||||
query.include('Signers');
|
||||
query.include('AuditTrail.UserPtr');
|
||||
query.include('Placeholders');
|
||||
query.notEqualTo('IsArchive', true)
|
||||
query.notEqualTo('IsArchive', true);
|
||||
const res = await query.first({ useMasterKey: true });
|
||||
if (res) {
|
||||
const acl = res.getACL();
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function getReport(request) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
console.log('err', err.message);
|
||||
if (err.code == 209) {
|
||||
return { error: 'Invalid session token' };
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import AWS from 'aws-sdk';
|
||||
const credentials = {
|
||||
accessKeyId: process.env.DO_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.DO_SECRET_ACCESS_KEY,
|
||||
};
|
||||
AWS.config.update({ credentials: credentials, region: process.env.DO_REGION });
|
||||
const spacesEndpoint = new AWS.Endpoint(process.env.DO_ENDPOINT);
|
||||
|
||||
const s3 = new AWS.S3({ endpoint: spacesEndpoint });
|
||||
|
||||
export default function getPresignedUrl(url) {
|
||||
// Create a new URL object
|
||||
const parsedUrl = new URL(url);
|
||||
// Get the pathname of the URL
|
||||
const pathname = parsedUrl.pathname;
|
||||
// Extract the filename from the pathname
|
||||
const filename = pathname.substring(pathname.lastIndexOf('/') + 1);
|
||||
|
||||
// presignedGETURL return presignedUrl with expires time
|
||||
const presignedGETURL = s3.getSignedUrl('getObject', {
|
||||
Bucket: process.env.DO_SPACE,
|
||||
Key: filename, //filename
|
||||
Expires: 160, //time to expire in seconds
|
||||
});
|
||||
return presignedGETURL;
|
||||
}
|
||||
+4
-4
@@ -11,7 +11,7 @@ const serverUrl = process.env.SERVER_URL,
|
||||
async function uploadFile(e, a) {
|
||||
try {
|
||||
var t = fs.readFileSync(a),
|
||||
s = new Parse.File(e, [...t]),
|
||||
s = new Parse.File(e, [...t], 'application/pdf'),
|
||||
r = (await s.save({ useMasterKey: !0 }), s.url());
|
||||
return { imageUrl: r };
|
||||
} catch (e) {
|
||||
@@ -111,11 +111,11 @@ async function sendDoctoWebhook(t, e, a, s) {
|
||||
}),
|
||||
a.save(null, { useMasterKey: !0 });
|
||||
} catch (e) {
|
||||
console.log('err save in contracts_Webhook', e);
|
||||
console.log('err save in contracts_Webhook', e.message);
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
console.log('Err send data to webhook', e);
|
||||
console.log('Err send data to webhook', e.message);
|
||||
try {
|
||||
var a = new Parse.Object('contracts_Webhook');
|
||||
a.set('Log', e?.status),
|
||||
@@ -126,7 +126,7 @@ async function sendDoctoWebhook(t, e, a, s) {
|
||||
}),
|
||||
a.save(null, { useMasterKey: !0 });
|
||||
} catch (e) {
|
||||
console.log('err save in contracts_Webhook', e);
|
||||
console.log('err save in contracts_Webhook', e.message);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user