Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Commit

Permalink
restrict access to temp directory and files, and add optional --cache…
Browse files Browse the repository at this point in the history
… CLI arg to pass down to op (#5)
  • Loading branch information
verterok authored Apr 7, 2022
1 parent 1580ac9 commit 3be1119
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions qute_1pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

CACHE_DIR = os.path.join(tempfile.gettempdir(), "qute_1pass")
os.makedirs(CACHE_DIR, exist_ok=True)
os.chmod(CACHE_DIR, 0o750)

SESSION_PATH = os.path.join(CACHE_DIR, "session")
SESSION_DURATION = timedelta(minutes=30)
Expand Down Expand Up @@ -52,6 +53,11 @@
help="Allow filling credentials on insecure sites",
action="store_true",
)
parser.add_argument(
"--cache",
help="store and use cached information",
action="store_true",
)


class Qute:
Expand Down Expand Up @@ -147,6 +153,7 @@ def login(cls):
if arguments.cache_session:
with open(SESSION_PATH, "w") as handler:
handler.write(session_id)
os.chmod(SESSION_PATH, 0o640)

return session_id

Expand Down Expand Up @@ -280,6 +287,7 @@ def _store_last_item(self, item):
last_item = {"host": extract_host(os.environ["QUTE_URL"]), "uuid": item["uuid"]}
with open(LAST_ITEM_PATH, "w") as handler:
handler.write(json.dumps(last_item))
os.chmod(LAST_ITEM_PATH, 0o640)

def _fill_single_field(self, field):
item = self._get_item()
Expand Down Expand Up @@ -333,6 +341,11 @@ def fill_totp(self):
if __name__ == "__main__":
arguments = parser.parse_args()

if arguments.cache:
# add --cache to cacheable commands with
CMD_OP_LIST_ITEMS += " --cache"
CMD_OP_GET_ITEM += " --cache"

# Prevent filling credentials in non-secure sites if not explicitly allwoed
if not arguments.allow_insecure_sites:
if urlsplit(os.environ["QUTE_URL"])[0] != "https":
Expand Down

0 comments on commit 3be1119

Please sign in to comment.