-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invisible script execution on Windows #264
This commit addresses an issue in the privacy.sexy desktop application where scripts executed as administrator on Windows were running in the background. This was observed in environments like Windows Pro VMs on Azure, where operations typically run with administrative privileges. Previously, the application used the `"$path"` shell command to execute scripts. This mechanism failed to activate the logic for requesting admin privileges if the app itself was running as an administrator. To resolve this, the script execution process has been modified to explicitly ask for administrator privileges using the `VerbAs` method. This ensures that the script always runs in a new `cmd.exe` window, enhancing visibility and user interaction. Other supporting changes: - Rename the generated script file from `run-{timestamp}-{extension}` er to `{timestamp}-privacy-script-{extension}` for clearer identification and better file sorting. - Refactor `ScriptFileCreator` to parameterize file extension and script name. - Rename `OsTimestampedFilenameGenerator` to `TimestampedFilenameGenerator` to better reflect its new and more scoped functionality after refactoring mentioned abvoe. - Remove `setAppName()` due to ineffective behavior in Windows. - Update `SECURITY.md` to highlight that the app doesn't require admin rights for standard operations. - Add `.editorconfig` settings for PowerShell scripts. - Add a integration test for script execution logic. Improve environment detection for more reliable test execution. - Disable application logging during unit/integration tests to keep test outputs clean and focused.
- Loading branch information
1 parent
7285842
commit b404a91
Showing
32 changed files
with
715 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/application/CodeRunner.ts → src/application/CodeRunner/CodeRunner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export interface CodeRunner { | ||
runCode( | ||
code: string, | ||
fileExtension: string, | ||
): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ScriptFileName = 'privacy-script' as const; |
4 changes: 3 additions & 1 deletion
4
src/infrastructure/CodeRunner/Creation/Filename/FilenameGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { ScriptFileNameParts } from '../ScriptFileCreator'; | ||
|
||
export interface FilenameGenerator { | ||
generateFilename(): string; | ||
generateFilename(scriptFileNameParts: ScriptFileNameParts): string; | ||
} |
47 changes: 0 additions & 47 deletions
47
src/infrastructure/CodeRunner/Creation/Filename/OsTimestampedFilenameGenerator.ts
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/infrastructure/CodeRunner/Creation/Filename/TimestampedFilenameGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ScriptFileNameParts } from '../ScriptFileCreator'; | ||
import { FilenameGenerator } from './FilenameGenerator'; | ||
|
||
export class TimestampedFilenameGenerator implements FilenameGenerator { | ||
public generateFilename( | ||
scriptFileNameParts: ScriptFileNameParts, | ||
date = new Date(), | ||
): string { | ||
validateScriptFileNameParts(scriptFileNameParts); | ||
const baseFileName = `${createTimeStampForFile(date)}-${scriptFileNameParts.scriptName}`; | ||
return scriptFileNameParts.scriptFileExtension ? `${baseFileName}.${scriptFileNameParts.scriptFileExtension}` : baseFileName; | ||
} | ||
} | ||
|
||
/** Generates a timestamp for the filename in 'YYYY-MM-DD_HH-MM-SS' format. */ | ||
function createTimeStampForFile(date: Date): string { | ||
return date | ||
.toISOString() | ||
.replace(/T/, '_') | ||
.replace(/:/g, '-') | ||
.replace(/\..+/, ''); | ||
} | ||
|
||
function validateScriptFileNameParts(scriptFileNameParts: ScriptFileNameParts) { | ||
if (!scriptFileNameParts.scriptName) { | ||
throw new Error('Script name is required but not provided.'); | ||
} | ||
if (scriptFileNameParts.scriptFileExtension?.startsWith('.')) { | ||
throw new Error('File extension should not start with a dot.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export interface ScriptFileCreator { | ||
createScriptFile(contents: string): Promise<string>; | ||
createScriptFile( | ||
contents: string, | ||
scriptFileNameParts: ScriptFileNameParts, | ||
): Promise<string>; | ||
} | ||
|
||
export interface ScriptFileNameParts { | ||
readonly scriptName: string; | ||
readonly scriptFileExtension: string | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.