@@ -23,6 +23,7 @@ const axios = require('axios')
23
23
const supportedLanguages = require ( '../enums/supportedLanguages' )
24
24
const { generate } = require ( '@builder.io/sqlgenerate' )
25
25
const parser = require ( 'sqlite-parser' )
26
+ const crypto = require ( 'crypto' )
26
27
27
28
const _runScript = async ( cmd , res , runMemoryCheck = false ) => {
28
29
let initialMemory = 0
@@ -802,6 +803,24 @@ const _preCleanUp = async () => {
802
803
}
803
804
}
804
805
806
+ const _checkIntegrity = async ( non_editable_files ) => {
807
+ for ( const [ filePath , expectedHash ] of Object . entries ( non_editable_files ) ) {
808
+ try {
809
+ const fullPath = path . join ( appConfig . multifile . workingDir , filePath )
810
+ const fileContent = await fs . promises . readFile ( fullPath )
811
+ const actualHash = crypto . createHash ( 'sha256' ) . update ( fileContent ) . digest ( 'hex' )
812
+ if ( actualHash !== expectedHash ) {
813
+ logger . warn ( `Integrity check failed for file: ${ filePath } ` )
814
+ return false
815
+ }
816
+ } catch ( error ) {
817
+ logger . error ( `Error reading file ${ filePath } : ${ error . message } ` )
818
+ return false
819
+ }
820
+ }
821
+ return true
822
+ }
823
+
805
824
const _executeMultiFile = async ( req , res , response ) => {
806
825
logger . info ( `serving ${ req . type } ` )
807
826
try {
@@ -815,6 +834,10 @@ const _executeMultiFile = async (req, res, response) => {
815
834
816
835
try {
817
836
let jasmineResults
837
+ if ( req ?. non_editable_files ) {
838
+ const isValidSubmission = await _checkIntegrity ( req . non_editable_files )
839
+ if ( ! isValidSubmission ) throw new Error ( `A non editable file has been modified, exiting...` )
840
+ }
818
841
if ( req . type === FRONTEND_STATIC_JASMINE ) {
819
842
const staticServerInstance = await _startStaticServer ( appConfig . multifile . staticServerPath )
820
843
jasmineResults = await _runTests ( )
0 commit comments