This post contains two solutions: a simple one and a more elaborate one.
Simple and crude solution based on \fbox
Let's start with a simple solution based on \fbox, that is easy to understand. We use \textbar for the vertical bar and provide a variant for unnumbered sections (\section*):
\documentclass[10pt,a4paper,twoside]{report}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{blindtext}
\definecolor{seccolor}{RGB}{41,48,57}
\newcommand{\hsp}{\hspace{8pt}}
\newcommand*{\sectionFont}{%
\Large\bfseries
}
% For \section
\titleformat{\section}[block]{\sectionFont}{}{0pt}{%
\fbox{\thesection \hsp \textcolor{seccolor}{\textbar}\hsp #1}}
% For \section*
\titleformat{name=\section, numberless}[block]{\sectionFont}{}{0pt}{%
\fbox{#1}}
\begin{document}
\chapter{Some chapter}
\section{Section title}
Foo bar.
\section*{Unnumbered section}
\blindtext
\end{document}

More elaborate solution using TikZ
If you want finer control than what \fbox allows (\fboxsep and \fboxrule), using a tikzpicture environment for the frame is a good alternative. Here is an example of what one can do this way. It implements a similar design as in JouleV's solution but tries to do a cleaner positioning in order to ensure that the baseline of the section number is always aligned with the baseline of the first line of the section tile. Since we have all the power of TikZ at hand, we also add a few bells and whistles that are just a few keywords away: rounded corners, drop shadow and a background fill of the title box.
(With a bit more hacking, it should even be possible to detect when the section title takes several lines, and only in this case use vertical centering for the section number!)
\documentclass[a4paper]{report}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{etoolbox}
\usepackage{varwidth}
\usepackage{calc}
\usepackage{blindtext}
\usepackage{tikz}
% Uncomment the following line if you use babel and have a recent enough TikZ:
% \usetikzlibrary{babel}
\usetikzlibrary{backgrounds}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{shadows}
% Essentially taken from <https://tex.stackexchange.com/a/482926/73317>
\tikzset{
max width/.style={
execute at begin node={\begin{varwidth}[t]{#1}},
execute at end node={\end{varwidth}}
}
}
% Colors used for decorated section titles
\definecolor{sectionDecoRuleColor}{RGB}{70,10,10}
\colorlet{sectionDecoBgColor}{yellow!10}
% Horizontal spacing used for decorated section titles
\newlength{\sectionDecoHsp}
\setlength{\sectionDecoHsp}{8pt}
\newcommand*{\sectionDecoRuleWidth}{0.4pt}
% Boolean flag indicating whether we are working with a \section or a \section*
\newtoggle{sectionDecoIsNumberedSec}
\makeatletter
% High-level command for section decorations. Two variants: one for \section
% and one for \section.
\newcommand{\sectionDecoration}{%
@ifstar{%
\togglefalse{sectionDecoIsNumberedSec}%
@sectionDecoration@nil % @nil passed instead of the section number
}{%
\toggletrue{sectionDecoIsNumberedSec}%
@sectionDecoration
}%
}
% #1: the section number (@nil if we are working for a \section)
% #2: the section title
\newcommand{@sectionDecoration}[2]{%
\begin{tikzpicture}
% The section number
\iftoggle{sectionDecoIsNumberedSec}{% case of \section
\node[inner xsep=\sectionDecoHsp, inner ysep=0, outer sep=0,
anchor=base west]
(section number) at (0,0)
{\strut #1};
}{% case of \section*
\node[inner sep=0, outer sep=0, anchor=base west]
(section number) at (0,0)
{\strut};
}
% The section title (which may occupy several lines)
\path let \p1 = ($(section number.east)-(section number.west)$),
\n1 = {\linewidth - veclen(\p1) - 2\sectionDecoHsp} in
node[inner xsep=\sectionDecoHsp, inner ysep=0, outer sep=0,
anchor=base west, max width=\n1]
(section title) at (section number.base east)
{\strut #2% Useful for testing: \rule{\n1}{1pt}%
\strut};
\begin{scope}[on background layer]
% The frame around {section number + title}
\node[inner sep=0, outer sep=0, draw, line width=\sectionDecoRuleWidth,
rounded corners,
fit={([xshift=0.5\pgflinewidth]section number.north west)
([xshift=-0.5\pgflinewidth]section title.south east)},
color=sectionDecoRuleColor, fill=sectionDecoBgColor, drop shadow]
(frame) {};
% The vertical line between section number and section title
\iftoggle{sectionDecoIsNumberedSec}{% case of \section
\draw[color=sectionDecoRuleColor, line width=\sectionDecoRuleWidth,
line cap=butt]
([yshift=-0.5\pgflinewidth]section title.north west) --
([yshift=0.5\pgflinewidth]section title.south west);
}{% no such line in the case of \section*
}
\end{scope}
% Display key points (only useful for debugging)
% \begin{scope}[overlay]
% \path[radius=1pt, fill=red] (section number.north west) circle {}
% (section number.north east) circle {};
% \node[draw,circle,green, inner sep=1.6pt] at (section title.north west) {};
% \end{scope}
\end{tikzpicture}%
}
\makeatother
\newcommand*{\sectionTitleFont}{\Large\bfseries}
% For \section
\titleformat{\section}[block]{\sectionTitleFont}{}{0pt}{%
\sectionDecoration{\thesection}{#1}}
% For \section*
\titleformat{name=\section, numberless}[block]{\sectionTitleFont}{}{0pt}{%
\sectionDecoration*{#1}}
\begin{document}
\chapter{Some chapter}
\section{A short section title}
\section{A very very very very very very very very very very
very very very very very very very very very very
long section title}
Foo bar.
\section*{An unnumbered section}
\blindtext
\end{document}

\strutto ensure the top (resp. bottom) lines from section number and title nodes are at the same height, rather than north west and a hardcoded minimum height... – frougon Apr 03 '19 at 10:23anchor. Maybe I will consider it when I have much free time. – Apr 03 '19 at 10:32