Skip to content
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
['name' => 'machineLease#revoke', 'url' => '/api/v1/app/leases/{id}/revoke', 'verb' => 'POST'],
// Session-authenticated admin/owner lease management.
['name' => 'leaseAdmin#index', 'url' => '/api/v1/applications/{id}/leases', 'verb' => 'GET'],
['name' => 'leaseAdmin#getPolicy', 'url' => '/api/v1/applications/{id}/lease-policy', 'verb' => 'GET'],
['name' => 'leaseAdmin#setPolicy', 'url' => '/api/v1/applications/{id}/lease-policy', 'verb' => 'PUT'],
['name' => 'leaseAdmin#revoke', 'url' => '/api/v1/leases/{leaseId}', 'verb' => 'DELETE'],

Expand Down
28 changes: 27 additions & 1 deletion browser-extension/src/background/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as api from '../lib/api.js'
import * as vault from '../lib/vault.js'
import { matchSecrets, hostOf } from '../lib/match.js'
import { classifyCapture } from '../lib/capture.js'
import { policyRefusal } from '../lib/policy.js'
import { buildPasskeyOrchestrator } from '../passkey/orchestrator.js'
import { senderOrigin } from '../passkey/rp.js'
import { computeTotp } from '../lib/totp-service.js'
Expand Down Expand Up @@ -186,12 +187,31 @@ async function totpCodeForHost(host) {
}

/**
* Save or update a captured credential (encrypted client-side).
* Why the org password policy refuses a captured password, or null
* (keepiq#746). Runs before anything is encrypted, as the web app does.
*
* @param {object} config The paired config.
* @param {string} value The captured password.
* @return {Promise<string|null>} The refusal reason, or null.
*/
async function policyRefusalFor(config, value) {
const policy = await api.fetchPolicy(config)
return policyRefusal(policy, value, (prefix) => api.breachRange(config, prefix))
}

/**
* Save or update a captured credential (encrypted client-side). A password
* the org policy refuses is not saved; the reason comes back as the error.
* @param payload
*/
async function doSaveCapture(payload) {
if (!vault.isUnlocked()) throw new Error('vault is locked')
const config = await api.loadConfig()
const refusal = await policyRefusalFor(config, payload.secret)
if (refusal !== null) {
pendingCapture = null
throw new Error(refusal)
}
const encryptedKey = await vault.encryptField(payload.secret)
const encryptedLogin = await vault.encryptField(payload.login || '')
const body = {
Expand Down Expand Up @@ -247,6 +267,12 @@ async function doCapture(capture) {
pendingCapture = null
return { action: 'none' }
}
// Say so in the page instead of offering a save the policy would refuse.
const refusal = await policyRefusalFor(config, capture.secret)
if (refusal !== null) {
pendingCapture = null
return { action: 'refused', reason: refusal }
}
pendingCapture.id = offer.id
return { action: offer.action, name: offer.name }
}
Expand Down
8 changes: 7 additions & 1 deletion browser-extension/src/content/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ async function captureCurrent() {
return
}
if (window.top !== window) return // one bar, in the top frame's view only
if (!offer || (offer.action !== 'save' && offer.action !== 'update')) return
if (!offer) return
if (offer.action === 'refused') {
// Nothing to decide: the policy refused the password, so only explain.
await showSavePrompt(offer, location.hostname)
return
}
if (offer.action !== 'save' && offer.action !== 'update') return
const choice = await showSavePrompt(offer, location.hostname)
try {
await chrome.runtime.sendMessage({
Expand Down
20 changes: 16 additions & 4 deletions browser-extension/src/content/save-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ export const PROMPT_TTL_MS = 30000
*
* @param {{action: string, name?: string}} offer The offer from the worker.
* @param {string} host The site host.
* @return {{text: string, primary: string}} The message and the main button.
* @return {{text: string, primary: string|null}} The message and the main button (null: none).
*/
export function promptCopy(offer, host) {
if (offer.action === 'refused') {
// The org password policy refuses this password (keepiq#746): explain,
// and offer no save button.
return {
text: `Keepiq did not save this login for ${host}. ${offer.reason || ''}`.trim(),
primary: null,
}
}
if (offer.action === 'update') {
return {
text: `Update the password of ${offer.name || host} in Keepiq?`,
Expand Down Expand Up @@ -77,12 +85,16 @@ export function showSavePrompt(
actions.className = 'actions'
const later = doc.createElement('button')
later.type = 'button'
later.textContent = 'Not now'
later.textContent = primary === null ? 'Close' : 'Not now'
const main = doc.createElement('button')
main.type = 'button'
main.className = 'primary'
main.textContent = primary
actions.append(later, main)
if (primary === null) {
actions.append(later)
} else {
actions.append(later, main)
}
bar.append(message, actions)
root.append(style, bar)
;(doc.body || doc.documentElement).appendChild(holder)
Expand All @@ -104,6 +116,6 @@ export function showSavePrompt(
}
main.addEventListener('click', onClick(offer.action))
later.addEventListener('click', onClick('dismiss'))
main.focus?.()
;(primary === null ? later : main).focus?.()
})
}
28 changes: 28 additions & 0 deletions browser-extension/src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ export function updateSecret(config, id, body) {
return request(config, 'PUT', '/api/v1/secrets/' + encodeURIComponent(id), body)
}

/**
* Read the org password policy, the same endpoint the web app reads
* (keepiq#746). Resolves to null when it cannot be read: an unavailable
* policy never blocks a save.
* @param config
*/
export async function fetchPolicy(config) {
try {
return await request(config, 'GET', '/api/settings/policy')
} catch {
return null
}
}

/**
* Fetch the breach suffix list for a 5-character SHA-1 prefix through the
* Keepiq proxy. Only the prefix leaves the browser, and it goes in the body,
* never in the URL, which the server logs next to the user (keepiq#866).
* @param config
* @param prefix
*/
export async function breachRange(config, prefix) {
const data = await request(config, 'POST', '/api/v1/breach-check/range', {
prefix,
})
return data?.suffixes ?? ''
}

/**
* Fetch the secret-type catalogue and return the id of a type by name/slug.
* @param config
Expand Down
48 changes: 48 additions & 0 deletions browser-extension/src/lib/policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* The org password policy on the extension's save path (keepiq#746).
*
* The web app refuses a manual value below the policy's strength floor, or
* one found in known breaches when the policy blocks those. A login saved
* from the extension skipped both. This module applies the SAME rules
* (`src/policy/rules.js`, bundled from the web app's source) to the same
* policy (`GET /api/settings/policy`), before the value is encrypted.
*
* Honest-client model, as in the web app: the server cannot see the value.
* A policy or breach service that does not answer never blocks a save.
*
* @spec openspec/specs/org-password-policies/spec.md#requirement-client-side-save-enforcement
*/

import { checkValueWith } from '../../../src/health/hibpMatch.js'
import { hibpBlockApplies, scoreShortfall } from '../../../src/policy/rules.js'

/** The type a login saved from the extension gets (the server default). */
export const EXTENSION_SAVE_TYPE = 'login'

/**
* Why the policy refuses this value, or null when it may be saved.
*
* @param {object|null} policy The policy from the server, or null when unavailable.
* @param {string} value The captured password (stays in the worker).
* @param {Function} fetchRange Resolves a 5-char SHA-1 prefix to the suffix list.
* @param {string} [typeName] The secret type the value is saved as.
* @return {Promise<string|null>} The refusal reason, or null.
*/
export async function policyRefusal(
policy,
value,
fetchRange,
typeName = EXTENSION_SAVE_TYPE,
) {
const shortfall = scoreShortfall(policy, typeName, value)
if (shortfall !== null) {
return `Password strength ${shortfall.score} is below your organisation's minimum of ${shortfall.floor}.`
}
if (hibpBlockApplies(policy, typeName, value)) {
const result = await checkValueWith(value, fetchRange)
if (result.status === 'breached') {
return `This password appears in known breaches ${result.count} times. Choose another.`
}
}
return null
}
20 changes: 19 additions & 1 deletion l10n/be.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,25 @@ OC.L10N.register(
"Your current master password": "Ваш бягучы галоўны пароль",
"%n emergency contact had an access request pending when your key rotation removed it. Check who asked before you add anyone back.": "У %n экстранага кантакту быў запыт доступу ў чаканні, калі змена ключа выдаліла яго. Праверце, хто запытваў, перш чым зноў кагосьці дадаваць.",
"%n emergency contacts had an access request pending when your key rotation removed them. Check who asked before you add anyone back.": "У экстраных кантактаў (%n) быў запыт доступу ў чаканні, калі змена ключа выдаліла іх. Праверце, хто запытваў, перш чым зноў кагосьці дадаваць.",
"These emergency contacts were not carried to your new key. Their emergency access was removed. Add them again from Emergency Access if you still want them.": "Гэтыя экстраныя кантакты не былі перанесены на ваш новы ключ. Іх экстраны доступ выдалены. Дадайце іх зноў у раздзеле Экстраны доступ, калі яны вам яшчэ патрэбныя."
"These emergency contacts were not carried to your new key. Their emergency access was removed. Add them again from Emergency Access if you still want them.": "Гэтыя экстраныя кантакты не былі перанесены на ваш новы ключ. Іх экстраны доступ выдалены. Дадайце іх зноў у раздзеле Экстраны доступ, калі яны вам яшчэ патрэбныя.",
"Renew root certificate": "Абнавіць каранёвы сертыфікат",
"This creates a new root and intermediate certificate. Every active encryption suite is signed again. You cannot undo this.": "Будуць створаны новы каранёвы і прамежкавы сертыфікаты. Кожны актыўны набор шыфравання будзе падпісаны зноў. Гэта нельга адмяніць.",
"Renew root": "Абнавіць корань",
"Root renewed. {n} encryption suites signed again.": "Корань абноўлены. Зноў падпісана набораў шыфравання: {n}.",
"Could not renew the root certificate.": "Не ўдалося абнавіць каранёвы сертыфікат.",
"Lease policy for this application": "Палітыка арэнды для гэтай праграмы",
"In force now: {default} seconds by default, {max} seconds at most.": "Зараз дзейнічае: {default} секунд па змаўчанні, не больш за {max} секунд.",
"Leases are not renewable": "Арэнду нельга падаўжаць",
"Lease policy saved.": "Палітыка арэнды захавана.",
"Leave a field empty to use the instance value.": "Пакіньце поле пустым, каб выкарыстаць значэнне экзэмпляра.",
"Instance value: {value}": "Значэнне экзэмпляра: {value}",
"Renewal": "Падаўжэнне",
"Use the instance value ({value})": "Выкарыстаць значэнне экзэмпляра ({value})",
"Allowed": "Дазволена",
"Not allowed": "Не дазволена",
"Save lease policy": "Захаваць палітыку арэнды",
"Only an administrator can change this policy.": "Змяніць гэтую палітыку можа толькі адміністратар.",
"Could not save the lease policy.": "Не ўдалося захаваць палітыку арэнды."
},
"nplurals=2; plural=(n != 1);"
)
20 changes: 19 additions & 1 deletion l10n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,25 @@
"Your current master password": "Ваш бягучы галоўны пароль",
"%n emergency contact had an access request pending when your key rotation removed it. Check who asked before you add anyone back.": "У %n экстранага кантакту быў запыт доступу ў чаканні, калі змена ключа выдаліла яго. Праверце, хто запытваў, перш чым зноў кагосьці дадаваць.",
"%n emergency contacts had an access request pending when your key rotation removed them. Check who asked before you add anyone back.": "У экстраных кантактаў (%n) быў запыт доступу ў чаканні, калі змена ключа выдаліла іх. Праверце, хто запытваў, перш чым зноў кагосьці дадаваць.",
"These emergency contacts were not carried to your new key. Their emergency access was removed. Add them again from Emergency Access if you still want them.": "Гэтыя экстраныя кантакты не былі перанесены на ваш новы ключ. Іх экстраны доступ выдалены. Дадайце іх зноў у раздзеле Экстраны доступ, калі яны вам яшчэ патрэбныя."
"These emergency contacts were not carried to your new key. Their emergency access was removed. Add them again from Emergency Access if you still want them.": "Гэтыя экстраныя кантакты не былі перанесены на ваш новы ключ. Іх экстраны доступ выдалены. Дадайце іх зноў у раздзеле Экстраны доступ, калі яны вам яшчэ патрэбныя.",
"Renew root certificate": "Абнавіць каранёвы сертыфікат",
"This creates a new root and intermediate certificate. Every active encryption suite is signed again. You cannot undo this.": "Будуць створаны новы каранёвы і прамежкавы сертыфікаты. Кожны актыўны набор шыфравання будзе падпісаны зноў. Гэта нельга адмяніць.",
"Renew root": "Абнавіць корань",
"Root renewed. {n} encryption suites signed again.": "Корань абноўлены. Зноў падпісана набораў шыфравання: {n}.",
"Could not renew the root certificate.": "Не ўдалося абнавіць каранёвы сертыфікат.",
"Lease policy for this application": "Палітыка арэнды для гэтай праграмы",
"In force now: {default} seconds by default, {max} seconds at most.": "Зараз дзейнічае: {default} секунд па змаўчанні, не больш за {max} секунд.",
"Leases are not renewable": "Арэнду нельга падаўжаць",
"Lease policy saved.": "Палітыка арэнды захавана.",
"Leave a field empty to use the instance value.": "Пакіньце поле пустым, каб выкарыстаць значэнне экзэмпляра.",
"Instance value: {value}": "Значэнне экзэмпляра: {value}",
"Renewal": "Падаўжэнне",
"Use the instance value ({value})": "Выкарыстаць значэнне экзэмпляра ({value})",
"Allowed": "Дазволена",
"Not allowed": "Не дазволена",
"Save lease policy": "Захаваць палітыку арэнды",
"Only an administrator can change this policy.": "Змяніць гэтую палітыку можа толькі адміністратар.",
"Could not save the lease policy.": "Не ўдалося захаваць палітыку арэнды."
},
"plurals": null
}
Loading
Loading