Skip to content

Commit e3743e0

Browse files
author
sachin-maheshwari
authored
Merge pull request #113 from topcoder-platform/dev
CI/CD and Security fixes
2 parents 9cc11b2 + f410bc9 commit e3743e0

File tree

5 files changed

+122
-13
lines changed

5 files changed

+122
-13
lines changed

.circleci/config.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
version: 2
2+
defaults: &defaults
3+
docker:
4+
- image: circleci/python:2.7.18-stretch-browsers
5+
install_dependency: &install_dependency
6+
name: Installation of build and deployment dependencies.
7+
command: |
8+
sudo apt install jq
9+
sudo pip install awscli --upgrade
10+
sudo pip install docker-compose
11+
install_deploysuite: &install_deploysuite
12+
name: Installation of install_deploysuite.
13+
command: |
14+
git clone --branch v1.4.5 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
15+
cp ./../buildscript/master_deploy.sh .
16+
cp ./../buildscript/buildenv.sh .
17+
cp ./../buildscript/awsconfiguration.sh .
18+
19+
builddeploy_steps: &builddeploy_steps
20+
- checkout
21+
- setup_remote_docker
22+
- run: *install_dependency
23+
- run: *install_deploysuite
24+
- run:
25+
name: Running build script.
26+
command: |
27+
./awsconfiguration.sh $DEPLOY_ENV
28+
source awsenvconf
29+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
30+
source buildenvvar
31+
./build.sh
32+
- deploy:
33+
name: Running MasterScript.
34+
command: |
35+
source awsenvconf
36+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
37+
source buildenvvar
38+
./master_deploy.sh -d CFRONT -e $DEPLOY_ENV -c true
39+
40+
jobs:
41+
# Build & Deploy against development backend
42+
"build-dev":
43+
<<: *defaults
44+
environment:
45+
DEPLOY_ENV: "DEV"
46+
LOGICAL_ENV: "dev"
47+
APPNAME: "tc-auth-lib"
48+
steps: *builddeploy_steps
49+
50+
"build-prod":
51+
<<: *defaults
52+
environment:
53+
DEPLOY_ENV: "PROD"
54+
LOGICAL_ENV: "prod"
55+
APPNAME: "tc-auth-lib"
56+
steps: *builddeploy_steps
57+
58+
workflows:
59+
version: 2
60+
build:
61+
jobs:
62+
# Development builds are executed on "develop" branch only.
63+
- "build-dev":
64+
context : org-global
65+
filters:
66+
branches:
67+
only:
68+
- dev
69+
70+
# Production builds are exectuted only on tagged commits to the
71+
# master branch.
72+
- "build-prod":
73+
context : org-global
74+
filters:
75+
branches:
76+
only: master
77+
78+
79+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# authlib
22
Mixed front-end lib for auth0 authorization
3+

build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
CONFFILENAME="./web-assets/js/setupAuth0WithRedirect.js"
4+
5+
perl -pi -e "s/\{\{DOMAIN\}\}/$DOMAIN/g" $CONFFILENAME
6+
perl -pi -e "s/\{\{AUTH0_CLIENT_ID\}\}/$AUTH0_CLIENT_ID/g" $CONFFILENAME
7+
perl -pi -e "s/\{\{LOGGERMODE\}\}/$LOGGERMODE/g" $CONFFILENAME
8+
perl -pi -e "s/\{\{AUTH0DOMAIN\}\}/$AUTH0DOMAIN/g" $CONFFILENAME
9+
10+
SIGNUPFILENAME="./web-assets/js/signup.js"
11+
perl -pi -e "s/\{\{DOMAIN\}\}/$DOMAIN/g" $SIGNUPFILENAME
12+
perl -pi -e "s/\{\{AUTH0DOMAIN\}\}/$AUTH0DOMAIN/g" $SIGNUPFILENAME
13+
14+
15+
mkdir dist
16+
cp -rv ./web-assets/css/* ./dist/
17+
cp -rv ./web-assets/js/* ./dist/
18+
cp -rv ./web-assets/images ./dist/
19+
cp -rv ./web-assets/static-pages/* ./dist/
20+
21+
22+

web-assets/js/setupAuth0WithRedirect.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const qs = (function (a) {
2323

2424
const authSetup = function () {
2525

26-
let domain = 'auth.topcoder.com';
27-
const clientId = 'UW7BhsnmAQh0itl56g1jUPisBO9GoowD';
26+
let domain = 'auth.{{DOMAIN}}';
27+
const clientId = '{{AUTH0_CLIENT_ID}}';
2828
const useLocalStorage = false;
2929
const useRefreshTokens = false;
3030
const v3JWTCookie = 'v3jwt';
@@ -38,7 +38,7 @@ const authSetup = function () {
3838
const utmSource = qs['utm_source'];
3939
const utmMedium = qs['utm_medium'];
4040
const utmCampaign = qs['utm_campaign'];
41-
const loggerMode = "prod";
41+
const loggerMode = "{{LOGGERMODE}}";
4242
const IframeLogoutRequestType = "LOGOUT_REQUEST";
4343
const enterpriseCustomers = ['zurich', 'cs'];
4444
const mode = qs['mode'] || 'signIn';
@@ -48,7 +48,7 @@ const authSetup = function () {
4848
if (utmSource &&
4949
(utmSource != 'undefined') &&
5050
(enterpriseCustomers.indexOf(utmSource) > -1)) {
51-
domain = "topcoder.auth0.com";
51+
domain = "{{AUTH0DOMAIN}}";
5252
returnAppUrl += '&utm_source=' + utmSource;
5353
}
5454

web-assets/js/signup.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var apiServerUrl = "https://api.topcoder.com/v3/users";
2+
var apiServerUrl = "https://api.{{DOMAIN}}/v3/users";
33
var qs = (function (a) {
44
if (a == "") return {};
55
var b = {};
@@ -46,14 +46,21 @@ $(document).ready(function () {
4646
if (result.result.status === 200 && result.result.content.valid) {
4747
$("#error").closest(".message").fadeOut();
4848
$("#error").html("");
49-
document.getElementById("signup").action = qs["formAction"];
50-
document.getElementById("state").value = qs["state"];
51-
document.getElementById("regSource").value = qs["regSource"];
52-
document.getElementById("utmSource").value = qs["utmSource"];
53-
document.getElementById("utmMedium").value = qs["utmMedium"];
54-
document.getElementById("utmCampaign").value = qs["utmCampaign"];
55-
document.getElementById("returnUrl").value = qs["returnUrl"];
56-
document.getElementById("signup").submit();
49+
let formAction = qs["formAction"];
50+
const opt1 = 'https://auth.{{DOMAIN}}/continue';
51+
const opt2 = 'https://{{AUTH0DOMAIN}}/continue';
52+
if (!formAction.startsWith(opt1) && !formAction.startsWith(opt2)) {
53+
// looks like XSS attack
54+
formAction = "#";
55+
}
56+
$('#signup').attr('action', formAction);
57+
$("#state").val(qs["state"]);
58+
$("#regSource").val(qs["regSource"]);
59+
$("#utmSource").val(qs["utmSource"]);
60+
$("#utmMedium").val(qs["utmMedium"]);
61+
$("#utmCampaign").val(qs["utmCampaign"]);
62+
$("#returnUrl").val(qs["returnUrl"]);
63+
$("#signup").submit();
5764
}
5865
},
5966
});

0 commit comments

Comments
 (0)