Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove API key from browser URL bar to improve security #15

Merged
merged 5 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions www/aw.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ display: inline;
cursor: pointer;
}

div#share-link {
border-top: 1px solid;
margin-top: 0.7em;
padding-top: 0.3em;
font-weight: normal;
font-size: small;
}

div#share-link .disabled {
color: #888888;
}

div#share-link a {
color: inherit;
text-decoration: none;
}

div#share-link span {
display: inline-block;
width: 45%;
text-align: center;
}

div.error {
background: #ed6a5a;
Expand Down
53 changes: 50 additions & 3 deletions www/aw.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,61 @@ loadActionables = function(url, apikey, service) {
});
}

setLink = function(type, url) {
var el = $('#'+type+'-link-url');
var cp = $('#'+type+'-link-copy');

if (url) {
el.attr("href", url);
el.removeClass("disabled");
cp.attr("href", "javascript:copyToClipboard('"+type+"');");
cp.css('visibility', 'visible');
} else {
el.removeAttr("href");
el.addClass("disabled");
cp.removeAttr("href");
cp.css('visibility', 'hidden');
}
}

getAbsolutePath = function() {
// https://stackoverflow.com/a/2864169/3888050
var loc = window.location;
var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}


populateLinks = function(url, apikey) {
const path = getAbsolutePath();

if (url) {
var shareLink = path+'?url='+encodeURIComponent(url);
setLink('share', shareLink);

if (apikey) {
var personalLink = path+'?url='+encodeURIComponent(url)+'&apikey='+encodeURIComponent(apikey);
setLink('personal', personalLink);
} else {
setLink('personal', null);
}
} else {
setLink('share', null);
}
}

copyToClipboard = function(type) {
var el = $('#'+type+'-link-url');
navigator.clipboard.writeText(el.attr("href"));
}

configAvailable = function(config) {
const service = config.ACTIONABLES_URL;
console.log("Using actionable service at " + service);

let url = urlParam('url');
let apikey = urlParam('apikey');
populateLinks(url, apikey);

$("#callparams [name='tr_tracker']").val(url)
$("#callparams [name='tr_apikey']").val(apikey)
Expand All @@ -285,9 +334,7 @@ configAvailable = function(config) {
$("#load").click(function(event) {
let url = $("#callparams [name='tr_tracker']").val()
let apikey = $("#callparams [name='tr_apikey']").val()

var newurl = '?url='+encodeURIComponent(url)+ '&apikey='+encodeURIComponent(apikey);
window.history.pushState({}, '', newurl);
populateLinks(url, apikey);

loadActionables(url, apikey, service);

Expand Down
4 changes: 4 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ <h2>Call Parameters</h2>
</div>
<div id="load">▶️</div>
</form>
<div id="share-link">
<span><a id="share-link-url" class="disabled">Share Link (tracker only)</a> <a id="share-link-copy">📋</a></span>
<span><a id="personal-link-url" class="disabled">Personal Link (with API key!)</a> <a id="personal-link-copy">📋</a></span>
</div>
</div>

</div>
Expand Down