I'm writing my thesis report in which citations inserted through citep en citet are blue, and the output of the citeauthor-command is the regular text color. I've achieved this using a combination of these answers.
The problem is that this negatively interferes with these commands in a separate environment (sidebox, created using tcolorbox) I've defined, and overrules specific hypersetup-settings defined for that environment. As the name suggests, I'm using this environment as a sort of sidebar/box, in which I'd like all the text (including citations) to be another color.
MWE
\documentclass[12pt]{report}
\usepackage[colorlinks=true, citecolor=blue]{hyperref}
\usepackage{natbib}
\usepackage{filecontents}
\usepackage{xpatch}
\usepackage[most]{tcolorbox}
\xpretocmd{\citeauthor}{\hypersetup{citecolor=black}}{}{}
\xpretocmd{\citeyear}{\hypersetup{citecolor=black}}{}{}
\xpretocmd{\citep}{\hypersetup{citecolor=blue}}{}{}
\xpretocmd{\citet}{\hypersetup{citecolor=blue}}{}{}
\newcounter{sidebox}
\newenvironment{sidebox}[1]{
\def\sideboxtext{Box}
\hypersetup{citecolor=red}
\newtcolorbox[use counter=sidebox]{sideboxinner}{%
empty,title={#1},
minipage boxed title,
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
enlarge left by=8mm,
width=\textwidth-8mm,
coltitle=red,coltext=red,fonttitle=,fontupper=\hypersetup{linkcolor=red,citecolor=red}\small,fontlower=\hypersetup{linkcolor=red,citecolor=red},
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=2.5mm,right=0mm,top=2pt,breakable,pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt
}
\begin{sideboxinner}
}
{
\end{sideboxinner}}
\begin{filecontents}{main.bib}
@article{myref,
title = {Fancy title},
journal = {Journal of Fancy Publications},
author = {Jane Dee and John Doe},
year = {2017},
pages = {293--311},
}
\end{filecontents}
\begin{document}
The work by \citeauthor{myref} was a fancy read~\citep{myref}. \citet{myref} was published in the text-coloured year of \citeyear{myref}.
\begin{sidebox}{This is a sidebox}
The work by \citeauthor{myref} was a fancy read~\citep{myref}. \citet{myref} was published in the text-coloured year of \citeyear{myref}.
\end{sidebox}
\bibliographystyle{plainnat}
\bibliography{main}
\end{document}
This compiles to the following, in which the citations in the sidebox are blue and black.

Removing the xpretocmd-lines yields this, in which the sidebox is formatted as I want it, but citeauthor and citeyear in the regular text are blue -- rather than black.

Attempts so far
Before coming here, I've made a few attempts to solve this on my own. As I reckon the xpretocmd-commands affect all citep-, citet-, citeauthor- and citeyear-commands, I've tried to redefine these conditionally, based on the environment (using \@currenvir, which is tcb@savebox for the sidebox, by the way). That doesn't work, presumably because these commands are executed in the preamble -- where the environment of use is still unknown.
I've also tried to redefine these xpretocmd-commands at the start of the sidebox-code (where I also change the hyperref-settinsg) and reset them at the end, without success.
Question
My question is fairly straightforward: how can I achieve the desired situation?

