"SyntaxError: Unexpected end of JSON input" when runing in Docker
Closed this issue · 12 comments
Hi, I'm trying to run the docker version and I got this error when I start the container:
/home/node/app/config.js:4 config.isSecure = config.dojoUrl.startsWith("https"); ^ TypeError: Cannot read property 'startsWith' of undefined at Object. (/home/node/app/config.js:4:34) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (/home/node/app/db.js:2:16) at Module._compile (internal/modules/cjs/loader.js:701:30)
I tried in Windows 10 and in a Kali Linux and got the same error.
Do I need to install something additional before running the docker image?
I'm really hopeful to get it running because it sounds as a really great tool to learn.
I already implemented insecure.inc and it is working without problem.
Did you configure the environment variables? From the error looks like the DOJO_URL is missing.
More details at this link: https://github.com/trendmicro/SecureCodingDojo/wiki/Running-the-training-portal
Hi Paul, thanks for your quick answer. I read the instructions and I followed, however it is not working. I'm running the insecureinc portal in port 8080. These are the values I'm using:
DOJO_URL=http://localhost:8080
DOJO_TARGET_URL=http://localhost:8080/insecureinc
DOJO_DB_HOST=localhost
DATA_DIR=/
CHALLENGE_MASTER_SALT=MyOwnSalt
CHALLENGE_URLS=https://localhost:8080/insecureinc
ENC_KEY=34CC4363FCC22A3EADBA68CE668DB8F7
ENC_KEY_IV=895D6F13D9F8DEDE39DBB6E4D82361DB
docker run -p 8081:8081 --name=training
-e DOJO_URL=$DOJO_URL
-e DOJO_TARGET_URL=$DOJO_TARGET_URL
-e DATA_DIR=$DATA_DIR
-e CHALLENGE_MASTER_SALT=$CHALLENGE_MASTER_SALT
--volume=$DATA_DIR:/dojofiles:consistent
securecodingdojo/trainingportal
And this is what I got:
undefined:1
undefined
^
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse ()
at Object. (/home/node/app/config.js:6:25)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/home/node/app/db.js:2:16)
Looks like this time is a different error. Could be because CHALLENGE_URLS is null and it's expecting an object. Can you try adding -e CHALLENGE_URLS="{}" after CHALLENGE_MASTER_SALT
Also be sure to change your encryption key/iv ;)
Let me know how it goes.
You are right. Now that part works and I'm getting a different error:
internal/crypto/hash.js:58
throw new ERR_INVALID_ARG_TYPE('data',
^
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, TypedArray, or DataView. Received type undefined
at Hash.update (internal/crypto/hash.js:58:11)
at getEncParams (/home/node/app/aescrypto.js:13:48)
at Object.exports.decrypt (/home/node/app/aescrypto.js:20:21)
at getGoogleStrategy (/home/node/app/auth.js:366:33)
at Object.exports.getPassport (/home/node/app/auth.js:443:49)
at Object. (/home/node/app/server.js:39:23)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
I really appreciate your support.
BTW, I configured it in CentOS according with the instructions and I get it working (with node server.js) but not in Docker.
Looks like this time around the code is trying to parse an empty ENC_GOOGLE_CLIENT_SECRET. Have you configured a GOOGLE_CLIENT_ID?
PS: I am planning to release a new image this week including significant changes. You may want to wait until then as the version in the image is not the same with the current version of the code.
Hi Paul, I have not configured the google client authentication. I want to use the local authentication, so I didn't fill that part as I understood it was optional. I'm curious how do you get what part is not working. It is because in the trace it appears the getGoogleStrategy ? I'm just trying to learn how you get it so I can try to look deeper before asking.
Sure, I can wait for the new version :)
docker-compose instructions here: https://github.com/trendmicro/SecureCodingDojo#try-it
Let me know how it goes!
I'm going to try and install docker again this week and will let you folks know how it goes.
@marevalo10 & @cabbagehead did you get it going? Let me know if I can close this issue.
I had to put everything on hold because work is so busy. Will try again later this week hopefully.
Closing this since the issue was solved. Let me know if you have any other issues.