BêtaOSM est en version bêta. Lisez ses limites connues (en anglais).
OSM

Notre code

Six morceaux du vrai code d’OSM, inchangés, tels qu’ils tournent sur votre serveur. Tout OSM est écrit ainsi.

Une mise à jour demande assez de signatures

Votre serveur n’installe une mise à jour que si assez de clés d’OSM l’ont signée, chaque clé comptée une fois.

def verify(raw, keys, threshold, namespace, ssh_keygen='ssh-keygen'):
    """A signed envelope -> its payload bytes, when at least `threshold` distinct keys of `keys` signed them."""
    payload, sigs = envelope(raw)
    keys = key_set(keys)
    if not isinstance(threshold, int) or isinstance(threshold, bool) or threshold < 1:
        raise ChannelError('The signature threshold is not valid.')
    good = set()
    for fp, sig in sigs:
        if fp in keys and fp not in good and ssh_verify(keys[fp], namespace, payload, sig, ssh_keygen):
            good.add(fp)
    if len(good) < threshold:
        raise ChannelError(f'A signed file has {len(good)} valid signature{"" if len(good) == 1 else "s"} of the '
                           f'{threshold} needed ({namespace}).')
    return payload
src/osm/channel.py, ligne 162: verify

Jamais plus ancienne, jamais expirée

Une liste de mises à jour plus ancienne que la dernière, ou expirée, est refusée : personne ne peut retenir votre serveur sur une ancienne version.

def _fresh(d, what, now, longest):
    issued, expires = _int(d, 'issued', what), _int(d, 'expires', what)
    if issued > now + DAY:
        raise ChannelError(f'{what} was made in the future: is this server\'s clock right?')
    if expires <= now:
        raise ChannelError(f'{what} ran out on {time.strftime("%Y-%m-%d", time.gmtime(expires))}.')
    if expires - issued > longest:
        raise ChannelError(f'{what} is valid for too long.')


def _not_older(d, payload, stored, field, what):
    if stored is None:
        return
    old = _object(stored, d['type'])
    if d[field] < old[field]:
        raise ChannelError(f'{what} is older than the one this server has seen ({field} {d[field]} < {old[field]}).')
    if d[field] == old[field] and payload != stored:
        raise ChannelError(f'{what} has the {field} of the one this server has, but other contents.')
src/osm/channel.py, ligne 203: _fresh, _not_older

Une deuxième étape illisible n’est pas « désactivée »

Quand le fichier de la connexion en deux étapes d’un compte ne peut pas être lu, OSM refuse la connexion. Le mot de passe seul n’entre jamais par erreur.

def read_two_step(user, path=None):
    """(Auth.totp_get; without the agent at hand: the Security check) An account's two-step sign-in, read from its file
    -> its record; None when it has none, or the file is another account's (other_account).  A file that is there but
    cannot be read, or is not one OSM wrote: OpError 503, never "none"."""
    try:
        with open(path or os.path.join(paths.TOTP_DIR, user + '.json'), encoding='utf-8') as f:
            d = json.load(f)
    except FileNotFoundError:
        return None
    except (OSError, ValueError) as e:                  # (ValueError: bad JSON, or bytes that are not UTF-8)
        _log_unreadable(user, getattr(e, 'strerror', None) or 'not valid JSON')
        raise OpError(_TOTP_UNREADABLE.format(user=user), 503)
    if not isinstance(d, dict) or not isinstance(d.get('enabled', False), bool) \
            or (d.get('enabled') and not (isinstance(d.get('secret'), str) and d['secret'])):
        _log_unreadable(user, 'not a two-step sign-in OSM wrote')
        raise OpError(_TOTP_UNREADABLE.format(user=user), 503)
    return None if other_account(d, user) else d
src/osm/agent/auth.py, ligne 190: read_two_step

Depuis Internet, un mot de passe ne suffit jamais

Par OSM Connect, chaque compte a besoin de son second facteur.

def may_sign_in(user, second_factor):
    """(auth, once the password or the passkey was right) Connect's rules for the account: one it lets in (who: the
    Administrators, plus the chosen groups, or every account), with a second factor.  OpError(403) otherwise."""
    from . import passkeys
    if not _who_allows(user, load()['rules']):
        raise OpError('This account may not sign in through OSM Connect. An Administrator can allow it on the server\'s '
                      'own network (Settings > Remote access).', 403)
    if not second_factor:
        rp = connect_rp()
        if any(k.get('rp_id') == rp for k in passkeys.keys_of(user)):
            raise OpError('Through OSM Connect a password alone is not enough: sign in with your passkey.', 403)
        raise OpError('Through OSM Connect an account needs two-step sign-in. Set it up on the server\'s own network '
                      '(My Account > Security), then sign in here with its code.', 403)
src/osm/agent/ops_connect.py, ligne 2022: may_sign_in

Un nom de fichier se prend en une seule étape

Déplacer un fichier ne remplace jamais celui qu’une autre personne vient d’y enregistrer.

def rename_noreplace(src, dst):
    """os.rename that never replaces what is at dst: FileExistsError then.  A check before a rename let a file made
    meanwhile (over SMB, by an app) be replaced without a word (the review of 10 Nov 2026).  Linux's renameat2 with
    RENAME_NOREPLACE; where the file system refuses that flag, a file is linked to dst and its old name removed (a link
    never replaces), and a folder is renamed onto an empty folder made for it (a rename never replaces one that is not
    empty); on one without links either, the check and the rename together, as before."""
    f = _libc_renameat2()
    if f:
        import ctypes
        if f(_AT_FDCWD, os.fsencode(src), _AT_FDCWD, os.fsencode(dst), RENAME_NOREPLACE) == 0:
            return
        e = ctypes.get_errno()
        if e not in (errno.EINVAL, errno.ENOSYS):
            raise OSError(e, os.strerror(e), src, None, dst)
    if os.path.isdir(src) and not os.path.islink(src):
        os.mkdir(dst, 0o700)                         # (FileExistsError when something is there)
        try:
            os.rename(src, dst)
        except OSError:
            try:
                os.rmdir(dst)
            except OSError:
                pass
            raise
        return
    try:
        os.link(src, dst, follow_symlinks=False)     # (FileExistsError when something is there)
    except FileExistsError:
        raise
    except OSError as e:
        if e.errno not in (errno.EPERM, errno.EOPNOTSUPP, errno.ENOTSUP, errno.EMLINK, errno.ENOSYS):
            raise
        if os.path.lexists(dst):                     # (no links on this file system: FAT, exFAT)
            raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST), dst)
        os.rename(src, dst)
        return
    try:
        os.unlink(src)
    except OSError:
        os.unlink(dst)                               # (its old name could not go: as it was)
        raise
src/osm/helpers/fileops.py, ligne 1686: rename_noreplace

Un bug devient un test

Quand nous corrigeons un bug, un test recrée l’instant exact où il s’est produit, et reste.

def test_a_file_made_meanwhile_is_never_replaced(self):
    """The other client's file is made at the very moment between op_transfer's look at the name and the move."""
    for op, real in (('move', fo._move), ('copy', fo._copy)):
        with self.subTest(op=op):
            src = self.put('in/report.docx', 'mine')

            def theirs_first(p, d, job=None, real=real):
                self.put('to/report.docx', 'theirs')
                return real(p, d, job)
            with mock.patch.object(fo, '_' + op, side_effect=theirs_first):
                said = self.transfer(op, src)
            self.assertEqual(said, f'There is something called report.docx in the target already. '
                                   f'Nothing was {"moved" if op == "move" else "copied"}.')
            self.assertEqual((self.read('to/report.docx'), self.read('in/report.docx')), ('theirs', 'mine'))
            self.assertEqual(self.hidden('to'), [])
            os.unlink(self.dst)
tests/test_sec_review2.py, ligne 80: test_a_file_made_meanwhile_is_never_replaced

Chaque changement, vérifié

  • Plus de 5 000 tests automatiques tournent à chaque changement, sur Debian 13, comme sur votre serveur.
  • Neuf sortes de vérifications doivent réussir avant qu’un changement puisse être construit : les tests, deux vérificateurs de code, les règles de la version compilée, la référence de l’API, les scripts du bureau avec leur allemand et leur français, les liens de la documentation, la remise à ce site web et le catalogue d’applications.
  • Notre modèle de menaces nomme chaque partie d’OSM exposée à un réseau, et ce qui y tient. Nous le revoyons sans cesse, et chaque problème qu’une revue trouve est corrigé avec le test qui l’aurait trouvé.

Les morceaux viennent d’OSM 0.3.0 (49ab072720fe). Vous avez trouvé quelque chose ? Écrivez à security@osm-os.com.