Skip to content
Closed
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
1 change: 1 addition & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ One file per piece of work, named for it:
| `mosh.md` | Mosh |
| `localization.md` | Translations |
| `bridge-stop-status.md` | AI Bridge: a stopped command's exit status |
| `bridge-audit-mode.md` | AI Bridge: an existing activity log is made owner-only |

Write for the people using the app, in the sections `CHANGELOG.md` uses:
`### Added`, `### Changed`, `### Fixed`, `### Security`. One line per change,
Expand Down
2 changes: 2 additions & 0 deletions docs/changes/bridge-audit-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Security
- An AI Bridge activity log file that an earlier build left readable by other accounts is now restricted to your user account the first time the app writes to it. Its folder was already restricted, so the file could not be reached.
9 changes: 9 additions & 0 deletions lib/services/bridge/bridge_audit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class BridgeAuditLog {

/// Where the log lives; null means `<appdata>/bridge`, found on first use.
final Directory? directory;

/// Whether this run has already made an existing log owner-only.
bool _existingChecked = false;

Directory? _resolved;

static const int defaultRotateBytes = 512 * 1024;
Expand Down Expand Up @@ -301,7 +305,12 @@ class BridgeAuditLog {
// spawned on every append.
await file.create();
await _ownerOnly(file.path);
} else if (!_existingChecked) {
// A log an earlier build left with the default mode is tightened the
// first time this run writes to it, not only when it is next rotated.
await _ownerOnly(file.path);
}
_existingChecked = true;

final handle = await file.open(mode: FileMode.append);
try {
Expand Down
18 changes: 18 additions & 0 deletions test/bridge_audit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,22 @@ void main() {
},
skip: Platform.isWindows,
);

test(
'a log an earlier build left readable is made owner-only on the first '
'write, without waiting for a rotation',
() async {
await recordOne(makeLog());
await Process.run('chmod', ['664', logFile.path]);
expect(logFile.statSync().mode & 0x1ff, 0x1b4); // 0664

// A new run of the app: a fresh log object over the same file.
final log = makeLog();
await recordOne(log);
expect(logFile.statSync().mode & 0x1ff, 0x180); // 0600
expect(File('${logFile.path}.1').existsSync(), isFalse);
expect(await log.recent(), hasLength(2));
},
skip: Platform.isWindows,
);
}
Loading