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

push monitor: increase token security #912

Merged
merged 9 commits into from
Oct 11, 2023
14 changes: 14 additions & 0 deletions db/knex_migrations/2023-10-11-1915-push-token-to-32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.up = function (knex) {
// update monitor.push_token to 32 length
return knex.schema
.alterTable("monitor", function (table) {
table.string("push_token", 32).alter();
});
};

exports.down = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.string("push_token", 20).alter();
});
};
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"successMessage": "Success Message",
"successMessageExplanation": "MQTT message that will be considered as success",
"recent": "Recent",
"Reset Token": "Reset Token",
"Done": "Done",
"Info": "Info",
"Security": "Security",
Expand Down
13 changes: 12 additions & 1 deletion src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
{{ $t("needPushEvery", [monitor.interval]) }}<br />
{{ $t("pushOptionalParams", ["status, msg, ping"]) }}
</div>
<button class="btn btn-primary" type="button" @click="resetToken">
{{ $t("Reset Token") }}
</button>
</div>

<!-- Keyword -->
Expand Down Expand Up @@ -847,6 +850,8 @@ import { sleep } from "../util";

const toast = useToast();

const pushTokenLength = 32;

const monitorDefaults = {
type: "http",
name: "",
Expand Down Expand Up @@ -1145,7 +1150,9 @@ message HealthCheckResponse {
"monitor.type"() {
if (this.monitor.type === "push") {
if (! this.monitor.pushToken) {
this.monitor.pushToken = genSecret(10);
// ideally this would require checking if the generated token is already used
// it's very unlikely to get a collision though (62^32 ~ 2.27265788 * 10^57 unique tokens)
this.monitor.pushToken = genSecret(pushTokenLength);
}
}

Expand Down Expand Up @@ -1348,6 +1355,10 @@ message HealthCheckResponse {
return true;
},

resetToken() {
this.monitor.pushToken = genSecret(pushTokenLength);
},

/**
* Submit the form data for processing
* @returns {void}
Expand Down