Compare commits

..
Author SHA1 Message Date
Jonas Lochmann ad458be961 Add workaround for session duration change logic bug 2023-12-18 01:00:00 +01:00
29 changed files with 4614 additions and 2330 deletions
-4
View File
@@ -41,10 +41,6 @@ If a whitelist was configured and the mail address is not within it: ``{"mailAdd
If a blacklist was configured and the mail server is within it: ``{"mailServerBlacklisted": true}``
If a temporarily blacklist was configured and the mail server is within it (used in case of known mail delivery issues): ``{"mailServerBlacklistedTemporarily": true}``
If the client is suspicious: ``{"blockedForIntegrityReasons": true}``
On success: a object with a ``mailLoginToken`` of the type string
#### example response
@@ -410,9 +410,6 @@
},
"perDay": {
"type": "boolean"
},
"e": {
"type": "number"
}
},
"additionalProperties": false,
@@ -1461,9 +1458,6 @@
},
"perDay": {
"type": "boolean"
},
"e": {
"type": "number"
}
},
"additionalProperties": false,
@@ -1,15 +0,0 @@
# Untitled number in SerializedParentAction Schema
```txt
https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e
```
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
## e Type
`number`
@@ -28,7 +28,6 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e") |
## ruleId
@@ -209,21 +208,3 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule
### perDay Type
`boolean`
## e
`e`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e")
### e Type
`number`
@@ -1,15 +0,0 @@
# Untitled number in SerializedParentAction Schema
```txt
https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e
```
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
## e Type
`number`
@@ -1,15 +0,0 @@
# Untitled number in SerializedParentAction Schema
```txt
https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/expiresAt
```
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
## expiresAt Type
`number`
@@ -28,7 +28,6 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelim
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e") |
## type
@@ -217,21 +216,3 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelim
### perDay Type
`boolean`
## e
`e`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e")
### e Type
`number`
-38
View File
@@ -899,7 +899,6 @@ Reference this group by using
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e") |
### ruleId
@@ -1081,24 +1080,6 @@ Reference this group by using
`boolean`
### e
`e`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e")
#### e Type
`number`
## Definitions group SerializedDeleteCategoryAction
Reference this group by using
@@ -4416,7 +4397,6 @@ Reference this group by using
| [dur](#dur-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
| [pause](#pause-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
| [perDay](#perday-1) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
| [e](#e-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e") |
### type
@@ -4606,24 +4586,6 @@ Reference this group by using
`boolean`
### e
`e`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e")
#### e Type
`number`
## Definitions group SerializedUpdateUserFlagsAction
Reference this group by using
-2
View File
@@ -57,5 +57,3 @@
- SIGN_SECRET
- used for signing tokens
- if not set or set to an empty string, then the features that depend on it are disabled
- UA_MAIL_BLOCKLIST
- List of user agents, separated by comma, that are not allowed to trigger sign in mails
+4553 -1901
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -38,11 +38,12 @@
"@types/lodash": "^4.14.166",
"@types/node": "^16.11.59",
"@types/nodemailer": "^6.4.4",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@types/umzug": "^2.3.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"eslint": "^8.7.0",
"rimraf": "^3.0.2",
"typescript": "^5.5.4",
"typescript": "^4.4.4",
"typescript-json-schema": "^0.52.0"
},
"dependencies": {
@@ -56,14 +57,14 @@
"jose": "^4.9.3",
"lodash": "^4.17.21",
"mariadb": "^2.5.2",
"nodemailer": "^7.0.9",
"nodemailer": "^6.7.2",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"pkijs": "^3.0.16",
"rate-limiter-flexible": "^2.1.15",
"sequelize": "^6.25.5",
"socket.io": "^4.0.1",
"umzug": "^3.8.1"
"sqlite3": "^4.0.0",
"umzug": "^2.3.0"
},
"optionalDependencies": {
"sqlite3": "^5.0.0"
+2 -4
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2023 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -58,9 +58,7 @@ const allTypes = [
const settings = {
required: true,
noExtraProps: true,
// otherwise it finds errors in dependencies that we don't care about
ignoreErrors: true
noExtraProps: true
};
const compilerOptions = {
+4 -17
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -32,12 +32,11 @@ export class UpdateTimelimitRuleAction extends ParentAction {
readonly sessionDurationMilliseconds: number
readonly sessionPauseMilliseconds: number
readonly perDay: boolean
readonly expiresAt?: number
constructor ({
ruleId, maximumTimeInMillis, dayMask, applyToExtraTimeUsage,
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
perDay, expiresAt
perDay
}: {
ruleId: string
maximumTimeInMillis: number
@@ -48,7 +47,6 @@ export class UpdateTimelimitRuleAction extends ParentAction {
sessionDurationMilliseconds: number
sessionPauseMilliseconds: number
perDay: boolean
expiresAt?: number
}) {
super()
@@ -61,7 +59,6 @@ export class UpdateTimelimitRuleAction extends ParentAction {
this.sessionDurationMilliseconds = sessionDurationMilliseconds
this.sessionPauseMilliseconds = sessionPauseMilliseconds
this.perDay = perDay
this.expiresAt = expiresAt
assertIdWithinFamily({ actionType, field: 'ruleId', value: ruleId })
@@ -95,17 +92,9 @@ export class UpdateTimelimitRuleAction extends ParentAction {
staticMessage: 'session duration lesser than zero'
})
}
if (expiresAt !== undefined) {
assertSafeInteger({ actionType, field: 'expiresAt', value: expiresAt })
if (expiresAt <= 0) {
throwOutOfRange({ actionType, field: 'expiresAt', value: expiresAt })
}
}
}
static parse = ({ ruleId, time, days, extraTime, start, end, dur, pause, perDay, e }: SerializedUpdateTimelimitRuleAction) => (
static parse = ({ ruleId, time, days, extraTime, start, end, dur, pause, perDay }: SerializedUpdateTimelimitRuleAction) => (
new UpdateTimelimitRuleAction({
ruleId,
maximumTimeInMillis: time,
@@ -115,8 +104,7 @@ export class UpdateTimelimitRuleAction extends ParentAction {
end: end ?? MinuteOfDay.MAX,
sessionDurationMilliseconds: dur ?? 0,
sessionPauseMilliseconds: pause ?? 0,
perDay: perDay ?? false,
expiresAt: e
perDay: perDay ?? false
})
)
}
@@ -132,5 +120,4 @@ export interface SerializedUpdateTimelimitRuleAction {
dur?: number
pause?: number
perDay?: boolean
e?: number
}
+3 -13
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2021 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,8 +17,7 @@
import { json } from 'body-parser'
import { Router } from 'express'
import { BadRequest, Forbidden } from 'http-errors'
import { config } from '../config'
import { BadRequest } from 'http-errors'
import { Database } from '../database'
import { sendLoginCode, signInByMailCode } from '../function/authentication/login-by-mail'
import { isMailAddressCoveredByWhitelist, isMailServerBlacklisted, sanitizeMailAddress } from '../util/mail'
@@ -26,17 +25,11 @@ import {
isSendMailLoginCodeRequest,
isSignInByMailCodeRequest
} from './validator'
import { analyze } from './integrity'
export const createAuthRouter = (database: Database) => {
const router = Router()
router.post('/send-mail-login-code-v2', json(), async (req, res, next) => {
const info = {
ua: req.headers['user-agent'],
cert: analyze(req),
}
try {
if (!isSendMailLoginCodeRequest(req.body)) {
throw new BadRequest()
@@ -52,15 +45,12 @@ export const createAuthRouter = (database: Database) => {
res.json({ mailAddressNotWhitelisted: true })
} else if (isMailServerBlacklisted(mail)) {
res.json({ mailServerBlacklisted: true })
} else if (config.uaMailBlocklist.indexOf(req.headers['user-agent'] || '') !== -1) {
throw new Forbidden()
} else {
const { mailLoginToken } = await sendLoginCode({
mail,
deviceAuthToken: req.body.deviceAuthToken,
locale: req.body.locale,
database,
info: Buffer.from(JSON.stringify(info), 'utf8')
database
})
res.json({ mailLoginToken })
-102
View File
@@ -1,102 +0,0 @@
import { X509Certificate } from 'crypto'
import { Request } from 'express'
import { fromBER, Sequence, Integer, OctetString, Set } from 'asn1js'
import { Certificate } from 'pkijs'
export interface CertInfo {
applicationCerts: Array<string>
}
export function analyze(req: Request): CertInfo | null {
try {
const certStr = req.headers['clientcertificate']
if (typeof certStr !== 'string') return null
const nativeCert = new X509Certificate(decodeURIComponent(certStr))
const now = Date.now()
const from = Date.parse(nativeCert.validFrom)
const to = Date.parse(nativeCert.validTo)
if (from > now || to < now) return null
if (from > to || from + 1000 * 60 * 5 < to) return null
const cert1 = fromBER(nativeCert.raw)
if (cert1.offset === -1) return null
const cert2 = new Certificate({ schema: cert1.result })
const androidExtension = (cert2.extensions || []).find((item) => item.extnID === '1.3.6.1.4.1.11129.2.1.17')?.extnValue?.valueBlock?.valueHexView
if (!androidExtension) return null
const androidExtensionParsed = fromBER(androidExtension)
if (androidExtensionParsed.offset === -1) return null
const androidExtensionSequence = androidExtensionParsed.result
if (!(androidExtensionSequence instanceof Sequence)) return null
const versionInteger = androidExtensionSequence.valueBlock.value[0]
if (!(versionInteger instanceof Integer)) return null
const versionValue = versionInteger.valueBlock.valueDec
const authorizationLists = androidExtensionSequence.valueBlock.value.slice(6, 8)
let applicationId = null
for (const authList of authorizationLists) {
if (!(authList instanceof Sequence)) continue
for (const authListItem of authList.valueBlock.value) {
if (
// version 1 does not provide this data structure
versionValue !== 1 &&
authListItem.idBlock.tagNumber === 709
) {
if (!('value' in authListItem.valueBlock)) continue
const value = (authListItem.valueBlock as unknown as { value: object }).value
if (!Array.isArray(value) || value.length !== 1) continue
if (value[0] instanceof OctetString) applicationId = value[0]
}
}
}
if (!applicationId) return null
const parsedApplicationId = fromBER(applicationId.valueBlock.valueHexView)
if (parsedApplicationId.offset === -1) return null
if (!(parsedApplicationId.result instanceof Sequence)) return null
const parsedApplicationIdInfo = parsedApplicationId.result.valueBlock.value
if (parsedApplicationIdInfo.length !== 2) return null
const signatureDigests = parsedApplicationIdInfo[1]
if (!(signatureDigests instanceof Set)) return null
const applicationCerts = []
for (const cert of signatureDigests.valueBlock.value) {
if (cert instanceof OctetString) {
applicationCerts.push(Buffer.from(cert.valueBlock.valueHexView).toString('hex'))
}
}
return {
applicationCerts
}
} catch (ex) {
return null
}
}
-6
View File
@@ -409,9 +409,6 @@ const definitions = {
},
"perDay": {
"type": "boolean"
},
"e": {
"type": "number"
}
},
"additionalProperties": false,
@@ -1420,9 +1417,6 @@ const definitions = {
},
"perDay": {
"type": "boolean"
},
"e": {
"type": "number"
}
},
"additionalProperties": false,
+3 -9
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2022 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -22,7 +22,6 @@ interface Config {
pingInterval: number
alwaysPro: boolean
signSecret: string
uaMailBlocklist: Array<string>
}
function parseYesNo (value: string) {
@@ -35,17 +34,12 @@ function parseYesNo (value: string) {
}
}
function parseList(list: string) {
return list.split(',').map((item) => item.trim()).filter((item) => item.length > 0)
}
class ParseYesNoException extends Error {}
export const config: Config = {
mailWhitelist: parseList(process.env.MAIL_WHITELIST || ''),
mailWhitelist: (process.env.MAIL_WHITELIST || '').split(',').map((item) => item.trim()).filter((item) => item.length > 0),
disableSignup: parseYesNo(process.env.DISABLE_SIGNUP || 'no'),
pingInterval: parseInt(process.env.PING_INTERVAL_SEC || '25', 10) * 1000,
alwaysPro: process.env.ALWAYS_PRO ? parseYesNo(process.env.ALWAYS_PRO) : false,
signSecret: process.env.SIGN_SECRET || '',
uaMailBlocklist: parseList(process.env.UA_MAIL_BLOCKLIST || '')
signSecret: process.env.SIGN_SECRET || ''
}
+2 -2
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2022 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -26,7 +26,7 @@ export const config = {
expireTimeRounding: 1000 * 60 * 15
}
export function calculateExpireTime(now: bigint): bigint {
export function calculateExpireTime(now: bigint): BigInt {
const expireBaseTime = now + BigInt(config.expireDelay)
const expireTime = expireBaseTime - expireBaseTime % BigInt(config.expireTimeRounding) + BigInt(config.expireTimeRounding)
@@ -1,39 +0,0 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
import { attributesVersion4 as ruleAttributes } from '../../timelimitrule'
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.addColumn('TimelimitRules', 'expiresAt', {
...ruleAttributes.expiresAt
}, {
transaction
})
})
}
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.removeColumn('TimelimitRules', 'expiresAt', { transaction })
})
}
+9 -17
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,26 +17,18 @@
import { resolve } from 'path'
import { Sequelize } from 'sequelize'
import { Umzug, SequelizeStorage } from 'umzug'
import * as Umzug from 'umzug'
export const createUmzug = (sequelize: Sequelize) => (
new Umzug({
storage: new SequelizeStorage({ sequelize }),
storage: 'sequelize',
storageOptions: {
sequelize
},
migrations: {
glob: resolve(__dirname, '../../../build/database/migration/migrations/*.js'),
resolve: ({ name, path }) => {
if (!path) throw new Error()
// eslint-disable-next-line @typescript-eslint/no-var-requires
const migration = require(path)
return {
name,
up: async () => migration.up(sequelize.getQueryInterface(), sequelize),
down: async () => migration.down(sequelize.getQueryInterface(), sequelize),
params: [sequelize.getQueryInterface(), sequelize],
path: resolve(__dirname, '../../../build/database/migration/migrations'),
pattern: /^\d+[\w-]+\.js$/
}
},
},
logger: console
})
)
+3 -20
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2021 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -41,13 +41,8 @@ interface TimelimitRuleAttributesVersion3 {
perDay: number
}
interface TimelimitRuleAttributesVersion4 {
expiresAt: string | null
}
type TimelimitRuleAttributes = TimelimitRuleAttributesVersion1 &
TimelimitRuleAttributesVersion2 & TimelimitRuleAttributesVersion3 &
TimelimitRuleAttributesVersion4
TimelimitRuleAttributesVersion2 & TimelimitRuleAttributesVersion3
export type TimelimitRuleModel = Sequelize.Model<TimelimitRuleAttributes> & TimelimitRuleAttributes
export type TimelimitRuleModelStatic = typeof Sequelize.Model & {
@@ -142,22 +137,10 @@ export const attributesVersion3: SequelizeAttributes<TimelimitRuleAttributesVers
}
}
export const attributesVersion4: SequelizeAttributes<TimelimitRuleAttributesVersion4> = {
expiresAt: {
type: Sequelize.BIGINT,
validate: {
min: 1
},
allowNull: true,
defaultValue: null
}
}
export const attributes: SequelizeAttributes<TimelimitRuleAttributes> = {
...attributesVersion1,
...attributesVersion2,
...attributesVersion3,
...attributesVersion4
...attributesVersion3
}
export const createTimelimitRuleModel = (sequelize: Sequelize.Sequelize): TimelimitRuleModelStatic => sequelize.define('TimelimitRule', attributes) as TimelimitRuleModelStatic
+3 -5
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2023 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -23,12 +23,11 @@ import { checkMailSendLimit } from '../../util/ratelimit-authmail'
import { generateAuthToken } from '../../util/token'
import { createAuthTokenByMailAddress } from './index'
export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database, info }: {
export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database }: {
mail: string
deviceAuthToken?: string
locale: string
database: Database
info: Buffer
// no transaction here because this is directly called from an API endpoint
}): Promise<{ mailLoginToken: string }> => {
let deviceName = null
@@ -83,8 +82,7 @@ export const sendLoginCode = async ({ mail, deviceAuthToken, locale, database, i
receiver: mail,
code,
locale,
deviceName,
info
deviceName
})
await database.transaction(async (transaction) => {
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2022 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -55,8 +55,7 @@ export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSel
endMinuteOfDay: action.rule.end,
sessionDurationMilliseconds: action.rule.sessionDurationMilliseconds,
sessionPauseMilliseconds: action.rule.sessionPauseMilliseconds,
perDay: action.rule.perDay ? 1 : 0,
expiresAt: action.rule.expiresAt ? action.rule.expiresAt.toString() : null
perDay: action.rule.perDay ? 1 : 0
}, { transaction: cache.transaction })
cache.categoriesWithModifiedTimeLimitRules.add(action.rule.categoryId)
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2022 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -81,8 +81,7 @@ export async function dispatchUpdateTimelimitRule ({
action.sessionDurationMilliseconds <= ruleEntry.sessionDurationMilliseconds &&
action.sessionPauseMilliseconds >= ruleEntry.sessionPauseMilliseconds
)) &&
(!action.perDay || ruleEntry.perDay || countOldAffectedDays <= 1) &&
(action.expiresAt === undefined || (ruleEntry.expiresAt !== null && action.expiresAt >= parseInt(ruleEntry.expiresAt, 10)))
(!action.perDay || ruleEntry.perDay || countOldAffectedDays <= 1)
if (!isAtLeastAsStrictAsPreviously) {
throw new CanNotRelaxRestrictionsSelfLimitException()
@@ -97,7 +96,6 @@ export async function dispatchUpdateTimelimitRule ({
ruleEntry.sessionDurationMilliseconds = action.sessionDurationMilliseconds
ruleEntry.sessionPauseMilliseconds = action.sessionPauseMilliseconds
ruleEntry.perDay = action.perDay ? 1 : 0
ruleEntry.expiresAt = action.expiresAt ? action.expiresAt.toString() : null
await ruleEntry.save({ transaction: cache.transaction })
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -45,8 +45,7 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
'endMinuteOfDay',
'sessionDurationMilliseconds',
'sessionPauseMilliseconds',
'perDay',
'expiresAt'
'perDay'
],
transaction
})).map((item) => ({
@@ -59,8 +58,7 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
endMinuteOfDay: item.endMinuteOfDay,
sessionDurationMilliseconds: item.sessionDurationMilliseconds,
sessionPauseMilliseconds: item.sessionPauseMilliseconds,
perDay: item.perDay,
expiresAt: item.expiresAt ? parseInt(item.expiresAt, 10) : undefined
perDay: item.perDay
}))
const getCategoryRulesVersion = (categoryId: string) => (
@@ -78,8 +76,7 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
end: item.endMinuteOfDay,
session: item.sessionDurationMilliseconds,
pause: item.sessionPauseMilliseconds,
perDay: item.perDay !== 0 ? true : false,
e: item.expiresAt
perDay: item.perDay !== 0 ? true : false
})),
version: getCategoryRulesVersion(categoryId)
}))
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2022 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -58,7 +58,7 @@ export const generateServerDataStatus = async ({
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
),
message: await getStatusMessage({ database, transaction }) || undefined,
apiLevel: 8
apiLevel: 7
}
if (familyEntry.deviceListVersion !== clientStatus.devices) {
+5 -19
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -29,12 +29,11 @@ export class TimelimitRule {
readonly sessionDurationMilliseconds: number
readonly sessionPauseMilliseconds: number
readonly perDay: boolean
readonly expiresAt?: number
constructor ({
ruleId, categoryId, maxTimeInMillis, dayMask, applyToExtraTimeUsage,
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
perDay, expiresAt
perDay
}: {
ruleId: string
categoryId: string
@@ -46,7 +45,6 @@ export class TimelimitRule {
sessionDurationMilliseconds: number
sessionPauseMilliseconds: number
perDay: boolean
expiresAt?: number
}) {
this.ruleId = ruleId
this.categoryId = categoryId
@@ -58,7 +56,6 @@ export class TimelimitRule {
this.sessionDurationMilliseconds = sessionDurationMilliseconds
this.sessionPauseMilliseconds = sessionPauseMilliseconds
this.perDay = perDay
this.expiresAt = expiresAt
assertIdWithinFamily(ruleId)
assertIdWithinFamily(categoryId)
@@ -91,14 +88,6 @@ export class TimelimitRule {
if (sessionDurationMilliseconds < 0 || sessionPauseMilliseconds < 0) {
throw new ParseTimeLimitRuleException()
}
if (expiresAt !== undefined) {
if (!Number.isSafeInteger(expiresAt)) throw new ParseTimeLimitRuleException()
if (expiresAt <= 0) {
throw new ParseTimeLimitRuleException()
}
}
}
serialize = (): SerializedTimeLimitRule => ({
@@ -110,11 +99,10 @@ export class TimelimitRule {
start: this.start,
end: this.end,
pause: this.sessionPauseMilliseconds,
dur: this.sessionDurationMilliseconds,
e: this.expiresAt
dur: this.sessionDurationMilliseconds
})
static parse = ({ ruleId, categoryId, time, days, extraTime, start, end, dur, pause, perDay, e }: SerializedTimeLimitRule) => (
static parse = ({ ruleId, categoryId, time, days, extraTime, start, end, dur, pause, perDay }: SerializedTimeLimitRule) => (
new TimelimitRule({
ruleId,
categoryId,
@@ -125,8 +113,7 @@ export class TimelimitRule {
end: end ?? MinuteOfDay.MAX,
sessionDurationMilliseconds: dur ?? 0,
sessionPauseMilliseconds: pause ?? 0,
perDay: perDay ?? false,
expiresAt: e
perDay: perDay ?? false
})
)
}
@@ -142,7 +129,6 @@ export interface SerializedTimeLimitRule {
dur?: number
pause?: number
perDay?: boolean
e?: number // expiresAt
}
export class ParseTimeLimitRuleException extends Error {}
+6 -16
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2024 Jonas Lochmann
* Copyright (C) 2019 - 2023 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -45,10 +45,9 @@ function createMailTemplateSender (templateName: string) {
const textTemplate = compileTemplate('text.ejs')
const htmlTemplate = compileTemplate('html.ejs')
const sendMail = async ({ receiver, params, info }: {
const sendMail = async ({ receiver, params }: {
receiver: string
params: object
info?: Buffer
}) => {
if (!mailTransport) {
throw new Error('can not send mails without mail config and without NODE_ENV=development')
@@ -57,9 +56,6 @@ function createMailTemplateSender (templateName: string) {
const subject = subjectTemplate(params).replace(/\n/g, ' ')
const text = textTemplate(params)
const html = htmlTemplate(params)
const headers: {[key: string]: string} = info ? {
'X-TlInfo': info.toString('base64')
} : {}
await new Promise<void>((resolve, reject) => {
mailTransport.sendMail({
@@ -67,8 +63,7 @@ function createMailTemplateSender (templateName: string) {
to: receiver,
subject,
text,
html,
headers
html
}, (err, info) => {
if (err) {
reject(err)
@@ -95,13 +90,9 @@ function createMailTemplateSender (templateName: string) {
const loginMailSender = createMailTemplateSender('login')
export const sendAuthenticationMail = async ({
receiver, code, locale, deviceName, info
receiver, code, locale, deviceName
}: {
receiver: string
code: string
locale: string
deviceName: string | null
info: Buffer
receiver: string, code: string, locale: string, deviceName: string | null
}) => {
await loginMailSender.sendMail({
receiver,
@@ -114,8 +105,7 @@ export const sendAuthenticationMail = async ({
deviceName,
deviceNameIntro: locale === 'de' ? 'Die Anmeldung wurde am Gerät' : 'The login was attempted at the device',
deviceNameOutro: locale === 'de' ? 'versucht.' : '.'
},
info
}
})
}
+1 -2
View File
@@ -11,8 +11,7 @@
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"skipLibCheck": true
"sourceMap": true
},
"include": [
"./src/**/*"